diff --git a/.github/workflows/e2e-extension.yml b/.github/workflows/e2e-extension.yml new file mode 100644 index 000000000..0ccb923e7 --- /dev/null +++ b/.github/workflows/e2e-extension.yml @@ -0,0 +1,41 @@ +name: e2e-cache + +on: + pull_request: + paths-ignore: + - '**.md' + push: + branches: + - main + - releases/* + paths-ignore: + - '**.md' + workflow_dispatch: + +permissions: + contents: read +jobs: + python-extension: + name: Test building extensions (Python ${{ matrix.python-version}}, ${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + python-version: ['3.9', 'pypy-3.9-v7.x'] + steps: + - uses: actions/checkout@v4 + - name: Setup Python + uses: ./ + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + - name: Install dependencies + run: pip install setuptools + - name: Build extension + run: pip install . + workdir: __tests__/data/extension/ + - name: Check output + run: | + output=$(python3 -c "import helloworld; helloworld.say_hello('world')") + test "$output" == "Hello, world!" diff --git a/.gitignore b/.gitignore index c087a78f2..0efb3fbae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# Ignore build/ and .egg-info/ directories of Python extension +__tests__/data/extension/build/ +__tests__/data/extension/helloworld.egg-info/ + # Ignore node_modules, ncc is used to compile nodejs modules into a single file in the releases branch node_modules/ __tests__/runner/* diff --git a/__tests__/data/extension/hello_world.c b/__tests__/data/extension/hello_world.c new file mode 100644 index 000000000..e9d6a6bf0 --- /dev/null +++ b/__tests__/data/extension/hello_world.c @@ -0,0 +1,27 @@ +#include + +static PyObject * say_hello(PyObject *self, PyObject *args) { + const char *name; + if (!PyArg_ParseTuple(args, "s", &name)) + return NULL; + PySys_WriteStdout("Hello, %s!", name); + Py_RETURN_NONE; +} + +static PyMethodDef HelloWorldMethods[] = { + {"say_hello", say_hello, METH_VARARGS, "Say hello"}, + {NULL, NULL, 0, NULL} +}; + +static struct PyModuleDef hello_world_module = { + PyModuleDef_HEAD_INIT, + "helloworld", + NULL, + -1, + HelloWorldMethods +}; + +PyMODINIT_FUNC PyInit_helloworld(void) +{ + return PyModule_Create(&hello_world_module); +} diff --git a/__tests__/data/extension/pyproject.toml b/__tests__/data/extension/pyproject.toml new file mode 100644 index 000000000..5c9e1a907 --- /dev/null +++ b/__tests__/data/extension/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "helloworld" +version = "1.0" diff --git a/__tests__/data/extension/setup.py b/__tests__/data/extension/setup.py new file mode 100644 index 000000000..c352b4ffb --- /dev/null +++ b/__tests__/data/extension/setup.py @@ -0,0 +1,10 @@ +from setuptools import Extension, setup + +setup( + ext_modules=[ + Extension( + name="helloworld", + sources=["hello_world.c"], + ), + ] +) diff --git a/dist/setup/index.js b/dist/setup/index.js index e28c3be0e..5e2c9ce08 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -90880,6 +90880,9 @@ function findPyPyVersion(versionSpec, architecture, updateEnvironment, checkLate // https://cmake.org/cmake/help/latest/module/FindPython3.html#module:FindPython3 core.exportVariable('Python3_ROOT_DIR', installDir); core.exportVariable('PKG_CONFIG_PATH', pythonLocation + '/lib/pkgconfig'); + if (utils_1.IS_WINDOWS) { + core.exportVariable('LIB', pythonLocation + '/libs'); + } core.addPath(pythonLocation); core.addPath(_binDir); } @@ -94123,4 +94126,4 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"] /******/ module.exports = __webpack_exports__; /******/ /******/ })() -; \ No newline at end of file +; diff --git a/src/find-pypy.ts b/src/find-pypy.ts index 9807878a9..3b99d38bf 100644 --- a/src/find-pypy.ts +++ b/src/find-pypy.ts @@ -93,6 +93,10 @@ export async function findPyPyVersion( // https://cmake.org/cmake/help/latest/module/FindPython3.html#module:FindPython3 core.exportVariable('Python3_ROOT_DIR', installDir); core.exportVariable('PKG_CONFIG_PATH', pythonLocation + '/lib/pkgconfig'); + // https://learn.microsoft.com/en-us/cpp/build/reference/linking?view=msvc-170#link-environment-variables + if (IS_WINDOWS) { + core.exportVariable('LIB', pythonLocation + '/libs'); + } core.addPath(pythonLocation); core.addPath(_binDir); }