Files
mtgodot-poc/tools/py_embed_android/main.c
T
shenleiandClaude Opus 5 b02c49bb2f spike(python): CPython 2.7.18 runs the 40250 root scripts on Android arm64
libpython2.7.a cross-builds with NDK 27.2 (API 24) after disabling
HAVE_LANGINFO_H; 30 C modules built in. On a OnePlus 13 (API 36) the
harness runs system.py -> prototype.RunApp() and imports the root modules
with results identical to macOS (66/74; the 8 failures are stub values or
dev-only scripts). py_embed_spike.py now isolates __main__ like
CPythonLauncher and reports stdlib usage.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 18:16:44 +09:00

34 lines
1.1 KiB
C

/* On-device check: embed CPython 2.7 the way CPythonLauncher does, then run py_embed_spike.py. */
#include <Python.h>
#include <stdio.h>
int main(int argc, char **argv)
{
const char *home = argc > 1 ? argv[1] : "/data/local/tmp/pyspike";
char buf[2048], spike[1024];
Py_NoSiteFlag = 1;
Py_IgnoreEnvironmentFlag = 1;
Py_DontWriteBytecodeFlag = 1;
Py_FrozenFlag = 1; /* no "Could not find platform libraries" noise */
Py_SetProgramName(argv[0]);
Py_SetPythonHome((char *)home);
Py_Initialize();
printf("Py_Initialize ok: %s\n", Py_GetVersion());
snprintf(buf, sizeof buf,
"import sys\n"
"sys.path[:] = ['%s/python27.zip']\n"
"sys.argv = ['py_embed_spike.py', '--out', '%s/result.txt']\n", home, home);
if (PyRun_SimpleString(buf) != 0)
return 2;
snprintf(spike, sizeof spike, "%s/py_embed_spike.py", home);
FILE *fp = fopen(spike, "r");
if (!fp) { perror(spike); return 3; }
int rc = PyRun_SimpleFileExFlags(fp, spike, 1, NULL);
printf("spike rc=%d\n", rc);
Py_Finalize();
return rc;
}