1
0
mirror of https://github.com/facebook/proxygen.git synced 2025-08-05 19:55:47 +03:00

getdeps: update FBPythonBinary.cmake to generate executable files on Windows

Summary:
On Windows, compile a small C executable to prepend to the zip file, to allow
the resulting executable files to be run directly on Windows, without needing
to explicitly invoke the Python interpreter to run the output file.

Reviewed By: wez

Differential Revision: D17733616

fbshipit-source-id: 989a93851412d0bbe1e7857aa9111db082f67a4c
This commit is contained in:
Adam Simpkins
2019-11-18 18:38:50 -08:00
committed by Facebook Github Bot
parent 3724751529
commit 833efc0ead
2 changed files with 92 additions and 16 deletions

View File

@@ -0,0 +1,27 @@
// Copyright (c) Facebook, Inc. and its affiliates.
#define Py_LIMITED_API 1
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <Python.h>
#include <stdio.h>
int wmain() {
/*
* This executable will be prepended to the start of a Python ZIP archive.
* Python will be able to directly execute the ZIP archive, so we simply
* need to tell Py_Main() to run our own file. Duplicate the argument list
* and add our file name to the beginning to tell Python what file to invoke.
*/
wchar_t** pyargv = malloc(sizeof(wchar_t*) * (__argc + 1));
if (!pyargv) {
fprintf(stderr, "error: failed to allocate argument vector\n");
return 1;
}
pyargv[0] = __wargv[0];
for (int n = 0; n < __argc; ++n) {
pyargv[n + 1] = __wargv[n];
}
return Py_Main(__argc + 1, pyargv);
}