Open jordemort opened 2 years ago
I gave this a shot. Here is a summary of what I did and hope it helps others.
MinGW ABI:
I used x86_64-w64-mingw32-gcc and lld in an MSYS2 shell with MSYSTEM set to MINGW64. This builds and works fine.
$ python
Python 3.10.11 (main, Apr 7 2023, 17:44:59) [GCC 12.2.0 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import starlark_go
>>> starlark_go.Starlark()
<starlark_go.starlark_go.Starlark object at 0x0000021eb0d77d90>
>>> s = starlark_go.Starlark()
>>> s
<starlark_go.starlark_go.Starlark object at 0x0000021eb0d75ef0>
>>> help(s)
Help on Starlark object:
class Starlark(builtins.object)
| Starlark(*, globals=None, print=None)
|
| Create a Starlark object. A Starlark object contains a set of global variables, which can be manipulated by executing Starlark code.
...
MSVC ABI:
I used clang on a developer command prompt with lld. I had to shim a couple of mingw libraries and this builds fine. Importing starlark_go
works. But constructing a Starlark
object hangs.
ntdll.dll!ZwWaitForSingleObject+0x14
KERNELBASE.dll!WaitForSingleObjectEx+0x8e
starlark_go.cp310-win_amd64.pyd!PyInit_starlark_go+0x635
starlark_go.cp310-win_amd64.pyd!Starlark_new+0x18
python310.dll!PyEval_EvalFrameDefault+0x2899
python310.dll!PyMapping_Check+0x1d5
python310.dll!PyEval_EvalCode+0x82
python310.dll!PyArena_Free+0x156
python310.dll!PyArena_Free+0xd6
python310.dll!PyRun_StringFlags+0x89
python310.dll!PyRun_SimpleStringFlags+0x41
python310.dll!PyMem_SetupAllocators+0x2ec
python310.dll!Py_RunMain+0x100
python310.dll!Py_RunMain+0x15
python310.dll!Py_Main+0x25
python.exe+0x1230
KERNEL32.DLL!BaseThreadInitThunk+0x14
ntdll.dll!RtlUserThreadStart+0x21
I sprinkled some fmt.Println
calls in Starlark_new
, but I do not see them printed. I guess this is stuck somewhere in the go runtime? I am not a golang person, so I have no idea what's going wrong.
Both of the builds above are by calling go directly: go build -x -buildmode=c-shared -o starlark_go.cp310-win_amd64.pyd --ldflags='--extldflags=-fuse-ld=lld'
. I don't use python setup.py bdist_wheel
because I can't figure out how to pass the arguments from python to go build
.
Building Windows wheels was blowing it because it couldn't find libpython to link against. Compilers on Windows are such a headache.
Investigate why, and fix it.