-
-
Save uranusjr/0821140136c4de900640f70d976af2ca to your computer and use it in GitHub Desktop.
Trying to set up a minimal CPython extension build environment
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
FROM python:3.7-windowsservercore | |
ENV VS_BUILDTOOLS '\ | |
https://download.visualstudio.microsoft.com/download/pr/11503713\ | |
/e64d79b40219aea618ce2fe10ebd5f0d/vs_BuildTools.exe' | |
COPY install-vs-tools.ps1 . | |
RUN .\install-vs-tools.ps1 | |
COPY hello.c . | |
COPY setup.py . | |
RUN python setup.py install | |
RUN python -c "import hello; hello.say('Here is some stuff...')" |
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
#include <stdio.h> | |
#include <Python.h> | |
static PyObject *hello_say(PyObject *self, PyObject *args) | |
{ | |
const char *msg; | |
if (!PyArg_ParseTuple(args, "s", &msg)) | |
return NULL; | |
fprintf(stdout, "Hello! %s\n", msg); | |
return Py_None; | |
} | |
static PyMethodDef HelloMethods[] = { | |
{"say", hello_say, METH_VARARGS, "Say stuff."}, | |
{NULL, NULL, 0, NULL}, | |
}; | |
static struct PyModuleDef hellomodule = { | |
PyModuleDef_HEAD_INIT, | |
"hello", | |
NULL, | |
-1, | |
HelloMethods, | |
}; | |
PyMODINIT_FUNC | |
PyInit_hello(void) | |
{ | |
PyObject *m = PyModule_Create(&hellomodule); | |
if (!m) | |
return NULL; | |
return m; | |
} |
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
Set-PSDebug -Trace 1 | |
Invoke-WebRequest -Uri "$env:VS_BUILDTOOLS" -OutFile 'vs_BuildTools.exe' | |
Start-Process 'vs_BuildTools.exe' -Wait -ArgumentList @( | |
'--add', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64', | |
'--add', 'Microsoft.VisualStudio.Component.VC.CoreBuildTools', | |
'--norestart', | |
'--quiet') |
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
from distutils.core import setup, Extension | |
setup( | |
name="hello", | |
version="1.0", | |
description="Hello!", | |
ext_modules=[Extension("hello", sources=["hello.c"])], | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment