Created
January 4, 2021 23:07
-
-
Save nbren12/81ba7810250b1b1c008c11574dc15a3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with import <nixpkgs> {}; | |
let | |
python = python3.withPackages (ps: [ps.cffi]); | |
in | |
stdenv.mkDerivation { | |
name = "example"; | |
inherit python; | |
buildInputs = [ stdenv python ]; | |
src = ./.; | |
doCheck = true; | |
doInstall = false; | |
installPhase = ""; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define PY_SSIZE_T_CLEAN | |
#include <Python.h> | |
int | |
main(int argc, char *argv[]) | |
{ | |
wchar_t *program = Py_DecodeLocale(argv[0], NULL); | |
if (program == NULL) { | |
fprintf(stderr, "Fatal error: cannot decode argv[0]\n"); | |
exit(1); | |
} | |
Py_SetProgramName(program); /* optional but recommended */ | |
Py_Initialize(); | |
int err; | |
PyRun_SimpleString("from time import time,ctime\n" | |
"print('Today is', ctime(time()))\n"); | |
PyRun_SimpleString("print('Importing cffi')\n"); | |
err = PyRun_SimpleString("import cffi"); | |
if (Py_FinalizeEx() < 0) { | |
exit(120); | |
} | |
PyMem_RawFree(program); | |
exit(err); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
${CC} -lpython3.8 -I${python}/include/python3.8 main.c | |
check: | |
./a.out | |
install: | |
mkdir -p ${out}/bin | |
cp a.out ${out}/bin/main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment