ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.36k stars 2.51k forks source link

Crosscompile CGO using zig 0.12 or newer #20689

Open ostcar opened 2 months ago

ostcar commented 2 months ago

Zig Version

0.14.0-dev.367+a57479afc

Steps to Reproduce and Observed Behavior

  1. Create a go sourcefile that uses cgo. For example:
    
    package main

import "C" import "fmt"

func main() { fmt.Println(C.int(10)) }


2. Create a go.mod file with `go mod init test`

3. Try to crosscompile this using go build and zig. For example to crosscompile from Linux to MacosX64 use:

GOOS=darwin GOARCH=amd64 CC='zig cc -target x86_64-macos' CGO_ENABLED=1 go build -buildmode c-archive

(The `-buildmode c-archive` is necessary or else there are linking problems that are not in the scope of this issue)

This fails with the error message:

runtime/cgo

error: unable to create compilation: AccessDenied


I am using the current version of go:

go version go version go1.22.4 linux/amd64



### Expected Behavior

It should create a shared library `test.a`.

This works with zig 0.11.0 but not with 0.12.0, 0.13.0 or the current master.
zhylmzr commented 2 months ago

Can you provide the version of go used, and the GOOS=darwin GOARCH=amd64 CC='zig cc -target x86_64-macos' CGO_ENABLED=1 go build -buildmode c-archive -x output?

ostcar commented 2 months ago

Here is the output with zig 0.11.0 and the current master.

$ zig version
0.11.0
$ GOOS=darwin GOARCH=amd64 CC='zig cc -target x86_64-macos' CGO_ENABLED=1 go build -buildmode c-archive -x
WORK=/tmp/go-build1775909776
mkdir -p $WORK/b046/
cd /usr/lib/go/src/runtime/cgo
TERM='dumb' CGO_LDFLAGS='"-O2" "-g" "-lpthread"' /usr/lib/go/pkg/tool/linux_amd64/cgo -objdir $WORK/b046/ -importpath runtime/cgo -import_runtime_cgo=false -import_syscall=false -exportheader=$WORK/b046/_cgo_install.h -- -I $WORK/b046/ -O2 -g -Wall -Werror -fno-stack-protector ./cgo.go
cd $WORK
zig cc -target x86_64-macos -fno-caret-diagnostics -O2 -g -c -x c - -o /dev/null || true
zig cc -target x86_64-macos -Qunused-arguments -O2 -g -c -x c - -o /dev/null || true
zig cc -target x86_64-macos -Wl,--no-gc-sections -O2 -g -x c - -o /dev/null || true
zig cc -target x86_64-macos -fdebug-prefix-map=a=b -O2 -g -c -x c - -o /dev/null || true
zig cc -target x86_64-macos -ffile-prefix-map=a=b -O2 -g -c -x c - -o /dev/null || true
zig cc -target x86_64-macos -gno-record-gcc-switches -O2 -g -c -x c - -o /dev/null || true
zig cc -target x86_64-macos -I /usr/lib/go/src/runtime/cgo -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b046=/tmp/go-build -gno-record-gcc-switches -fno-common -frandom-seed=1 -O2 -g -c -x c - -o /dev/null || true
cd $WORK/b046
TERM='dumb' zig cc -target x86_64-macos -I /usr/lib/go/src/runtime/cgo -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b046=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b046/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/lib/go=/_/GOROOT -frandom-seed=_a284911PGKtvqDsVC9b -o $WORK/b046/_x001.o -c _cgo_export.c
TERM='dumb' zig cc -target x86_64-macos -I /usr/lib/go/src/runtime/cgo -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b046=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b046/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/lib/go=/_/GOROOT -frandom-seed=_a284911PGKtvqDsVC9b -o $WORK/b046/_x002.o -c cgo.cgo2.c
cd /usr/lib/go/src/runtime/cgo
TERM='dumb' zig cc -target x86_64-macos -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b046=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b046/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/lib/go=/_/GOROOT -frandom-seed=_a284911PGKtvqDsVC9b -o $WORK/b046/_x003.o -c gcc_context.c
TERM='dumb' zig cc -target x86_64-macos -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b046=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b046/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/lib/go=/_/GOROOT -frandom-seed=_a284911PGKtvqDsVC9b -o $WORK/b046/_x004.o -c gcc_darwin_amd64.c
TERM='dumb' zig cc -target x86_64-macos -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b046=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b046/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/lib/go=/_/GOROOT -frandom-seed=_a284911PGKtvqDsVC9b -o $WORK/b046/_x005.o -c gcc_libinit.c
TERM='dumb' zig cc -target x86_64-macos -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b046=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b046/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/lib/go=/_/GOROOT -frandom-seed=_a284911PGKtvqDsVC9b -o $WORK/b046/_x006.o -c gcc_setenv.c
TERM='dumb' zig cc -target x86_64-macos -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b046=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b046/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/lib/go=/_/GOROOT -frandom-seed=_a284911PGKtvqDsVC9b -o $WORK/b046/_x007.o -c gcc_stack_darwin.c
TERM='dumb' zig cc -target x86_64-macos -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b046=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b046/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/lib/go=/_/GOROOT -frandom-seed=_a284911PGKtvqDsVC9b -o $WORK/b046/_x008.o -c gcc_traceback.c
TERM='dumb' zig cc -target x86_64-macos -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b046=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b046/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/lib/go=/_/GOROOT -frandom-seed=_a284911PGKtvqDsVC9b -o $WORK/b046/_x009.o -c gcc_util.c
TERM='dumb' zig cc -target x86_64-macos -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b046=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b046/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/lib/go=/_/GOROOT -frandom-seed=_a284911PGKtvqDsVC9b -o $WORK/b046/_x010.o -c gcc_amd64.S
cd $WORK/b046
TERM='dumb' zig cc -target x86_64-macos -I /usr/lib/go/src/runtime/cgo -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b046=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b046/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/lib/go=/_/GOROOT -frandom-seed=_a284911PGKtvqDsVC9b -o $WORK/b046/_cgo_main.o -c _cgo_main.c
cd /home/ossi/src/test
TERM='dumb' zig cc -target x86_64-macos -I /usr/lib/go/src/runtime/cgo -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b046=/tmp/go-build -gno-record-gcc-switches -fno-common -o $WORK/b046/_cgo_.o $WORK/b046/_cgo_main.o $WORK/b046/_x001.o $WORK/b046/_x002.o $WORK/b046/_x003.o $WORK/b046/_x004.o $WORK/b046/_x005.o $WORK/b046/_x006.o $WORK/b046/_x007.o $WORK/b046/_x008.o $WORK/b046/_x009.o $WORK/b046/_x010.o -O2 -g -lpthread
TERM='dumb' /usr/lib/go/pkg/tool/linux_amd64/cgo -dynpackage cgo -dynimport $WORK/b046/_cgo_.o -dynout $WORK/b046/_cgo_import.go -dynlinker
mkdir -p $WORK/b001/
TERM='dumb' CGO_LDFLAGS='"-O2" "-g"' /usr/lib/go/pkg/tool/linux_amd64/cgo -objdir $WORK/b001/ -importpath test -exportheader=$WORK/b001/_cgo_install.h -- -I $WORK/b001/ -O2 -g ./main.go
cd $WORK/b001
TERM='dumb' zig cc -target x86_64-macos -I /home/ossi/src/test -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b001/ -O2 -g -frandom-seed=LFdcApRvjMenFDQZlsyU -o $WORK/b001/_x001.o -c _cgo_export.c
TERM='dumb' zig cc -target x86_64-macos -I /home/ossi/src/test -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b001/ -O2 -g -frandom-seed=LFdcApRvjMenFDQZlsyU -o $WORK/b001/_x002.o -c main.cgo2.c
TERM='dumb' zig cc -target x86_64-macos -I /home/ossi/src/test -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b001/ -O2 -g -frandom-seed=LFdcApRvjMenFDQZlsyU -o $WORK/b001/_cgo_main.o -c _cgo_main.c
cd /home/ossi/src/test
TERM='dumb' zig cc -target x86_64-macos -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -fno-common -o $WORK/b001/_cgo_.o $WORK/b001/_cgo_main.o $WORK/b001/_x001.o $WORK/b001/_x002.o -O2 -g
TERM='dumb' /usr/lib/go/pkg/tool/linux_amd64/cgo -dynpackage main -dynimport $WORK/b001/_cgo_.o -dynout $WORK/b001/_cgo_import.go
cat >/tmp/go-build1775909776/b001/importcfg.link << 'EOF' # internal
packagefile test=/home/ossi/.cache/go-build/d6/d63e39aa9f801811477c46cacd57130c2f575c58cb4eacb46322a63f04a4cbb6-d
packagefile fmt=/home/ossi/.cache/go-build/b9/b9c0b5f3afd5d0875f582a6d22664e0ec1b7d6924bb65fe6000dc40865af4dd5-d
packagefile runtime/cgo=/home/ossi/.cache/go-build/e1/e1ff14034dbd1f76ce647f36fea82a95904efb9f0e554fb4f1658baf2c7baac2-d
packagefile syscall=/home/ossi/.cache/go-build/1d/1d5361fd2ec3791efa731251acc73202fb1458b6e211e85c6070b6e99d2791a0-d
packagefile runtime=/home/ossi/.cache/go-build/f3/f33d7ab08f4372f0220f280b60e0a0e287da0c4f60b0701ebb1d8cc3f36ce2ef-d
packagefile errors=/home/ossi/.cache/go-build/a0/a0f6451de6cf317a7f51a1dea19cafde3a937b015de4b25f489f41193f28d8fb-d
packagefile internal/fmtsort=/home/ossi/.cache/go-build/b5/b582583f0d481b18305b291093d385fedf34e9c973b3f1a4d5d812ec511a767c-d
packagefile io=/home/ossi/.cache/go-build/ee/eeb8c50baa4f5614a2fe9e79354a5cc4d88c119f3e62b3fb05f8580a15225bf9-d
packagefile math=/home/ossi/.cache/go-build/47/47d556bbf06306fcd58f59050a96f40550a3eebd7bc0c3d2b019a345f01ba6eb-d
packagefile os=/home/ossi/.cache/go-build/95/95dc5a3a53dd7a2f7e6415d54ad1eb2e1318da7d5e10f302834f4ea52badb58d-d
packagefile reflect=/home/ossi/.cache/go-build/bd/bd413776e80d23e35e67dcaeb776a2318b8e1b4c3fb0846465daf2e553b72658-d
packagefile sort=/home/ossi/.cache/go-build/d0/d0ba1419f696593638b8ccf986b8d34e2768beb44f576aef3f20f945fe220871-d
packagefile strconv=/home/ossi/.cache/go-build/9b/9ba4e24cbf82dc8baf911b897b6cfac48e6b87b46c957ec06b1c9b444cd01704-d
packagefile sync=/home/ossi/.cache/go-build/a0/a0f4ea60bd5fd3e7fab49d8202c57b75e1c6e893102b4543c30a4e79cb15b349-d
packagefile unicode/utf8=/home/ossi/.cache/go-build/4f/4faff1ed766943bcf794d35c7352cb6e3329413755c9459906ecd6a46997fda8-d
packagefile runtime/internal/sys=/home/ossi/.cache/go-build/38/384c91ad2f5796a3302088cf2f843b22ef54658f00e26f2d35f8b6d6e270b179-d
packagefile sync/atomic=/home/ossi/.cache/go-build/c0/c0b9a75eb1abd5c5ddbd93a12022c536bd1662ff6b48927b4922991ba8704539-d
packagefile internal/abi=/home/ossi/.cache/go-build/29/298201f7e185f3764bfa2496291756ee3619901d1c34bad20f0b3479406c53fa-d
packagefile internal/bytealg=/home/ossi/.cache/go-build/06/067f7e7e456aed950457b6c201611d39554723fc184d65de54c36de81ca31ae0-d
packagefile internal/itoa=/home/ossi/.cache/go-build/f0/f0e8d97d93867768aa15cb8686c67aba8eba7979342c7ae873d0d432d0843acc-d
packagefile internal/oserror=/home/ossi/.cache/go-build/3f/3f6dbf808f48b83f9c8bdcc9d6901831028c235263cc9fb432c92241152e86fc-d
packagefile internal/race=/home/ossi/.cache/go-build/7d/7d193b61f73497a468f9b81c7e42e018d064b2fb033931c1d6c29ce089fa10c5-d
packagefile internal/chacha8rand=/home/ossi/.cache/go-build/d7/d7336648e5ba2da799312953a683ef2aa0800919e317f786e06b16653842185f-d
packagefile internal/coverage/rtcov=/home/ossi/.cache/go-build/e3/e370ad174053e189c4c18b535208926d2e540979cac0c6a057866007664dd533-d
packagefile internal/cpu=/home/ossi/.cache/go-build/97/977188c155832a3709bb47673c059eda95a9bd204abf59e74a2c7a637b29643b-d
packagefile internal/goarch=/home/ossi/.cache/go-build/39/39af0d40fdaad8f4bbaf2b628b4dbb88e7ab803393f2f3325f671f4bf0f3d643-d
packagefile internal/godebugs=/home/ossi/.cache/go-build/96/96ac6147fc8fb7bc84324f2b5ec90fb0311fb6f03ec30df2927440849fe343f2-d
packagefile internal/goexperiment=/home/ossi/.cache/go-build/e9/e92ca67a435628f2912744b69c6bdd942e24c45f2c57b5c1aae4c861a5642fc0-d
packagefile internal/goos=/home/ossi/.cache/go-build/59/59896cb4c1bee6630e40f6d22d704dac8796f768dcce2e423bf11e892d53a4b6-d
packagefile runtime/internal/atomic=/home/ossi/.cache/go-build/7a/7a45bc7e0a5b7d25a98f617afdc114cb2f06f3ba34ff1ce6665048bb9e510f38-d
packagefile runtime/internal/math=/home/ossi/.cache/go-build/02/0209eb63c4e932ce127d89276fb89d48b9ffb9e48af246a858bbd54f0f13f4ca-d
packagefile internal/reflectlite=/home/ossi/.cache/go-build/97/9734c650ebd2d76a1243929b2977e8381a1b9281ba4977759c3cf1fc06b6361c-d
packagefile math/bits=/home/ossi/.cache/go-build/58/58c0262fefe71a7ec366c6e86099117d6efba73ff8c3f024d397a8667d2ecce8-d
packagefile internal/poll=/home/ossi/.cache/go-build/78/788832714bcad7e9bb7d38d969bc199352af5887d79a8aee107b0a1aab355712-d
packagefile internal/safefilepath=/home/ossi/.cache/go-build/56/568dc321851ed5064aadc52b48b87724a259cc1a11b523ad77f6906ae8d8a1a9-d
packagefile internal/syscall/execenv=/home/ossi/.cache/go-build/57/574c581dcfa90c6f170c185ba46279bbcda4185271889e268f7c485cb56ebe2c-d
packagefile internal/syscall/unix=/home/ossi/.cache/go-build/11/1163657f7626235c9a5b19c13ba9382c53bbf36864bf5a8c235c9ca51782e2a3-d
packagefile internal/testlog=/home/ossi/.cache/go-build/67/67df5625bc1e9eaa0d94ec74062e4a0a1e7e387eb5aed56e448816cecdcef681-d
packagefile io/fs=/home/ossi/.cache/go-build/ba/ba47c63a66c47af77db039b560027b79d63c6e26b529619743401728f4265a54-d
packagefile time=/home/ossi/.cache/go-build/52/52af7d050c09719214cddd33a32de42cfc54594c6d9f21fdc8a368ff04a6fc6a-d
packagefile internal/unsafeheader=/home/ossi/.cache/go-build/4f/4fbd3499c94e8ca5a3fd8d0578e6a6cf171bcebf171e5b587c7d205fb6951ec1-d
packagefile unicode=/home/ossi/.cache/go-build/cc/ccb0a054abca8df1b3abf09628b158312ba66b59dacb65004aaa290dd16befb3-d
packagefile slices=/home/ossi/.cache/go-build/67/67dfb21e108e6063354e6984d31780efc72bb9ee15c48abfa1c8f311e5ed6aff-d
packagefile path=/home/ossi/.cache/go-build/6f/6f322987c6694731c750718c647c77c51005337d1ec2b8055dd2b38de8f35103-d
packagefile cmp=/home/ossi/.cache/go-build/05/05e281c857eb4cf79d30e0f95c40607e7416664a56c14f81a6e087a1f8b2a346-d
modinfo "0w\xaf\f\x92t\b\x02A\xe1\xc1\a\xe6\xd6\x18\xe6path\ttest\nmod\ttest\t(devel)\t\nbuild\t-buildmode=c-archive\nbuild\t-compiler=gc\nbuild\tCGO_ENABLED=1\nbuild\tCGO_CFLAGS=\nbuild\tCGO_CPPFLAGS=\nbuild\tCGO_CXXFLAGS=\nbuild\tCGO_LDFLAGS=\nbuild\tGOARCH=amd64\nbuild\tGOOS=darwin\nbuild\tGOAMD64=v1\n\xf92C1\x86\x18 r\x00\x82B\x10A\x16\xd8\xf2"
EOF
mkdir -p $WORK/b001/exe/
cd .
/usr/lib/go/pkg/tool/linux_amd64/link -o $WORK/b001/exe/a.out.a -importcfg $WORK/b001/importcfg.link -buildmode=c-archive -buildid=7D4SZnYnAMBz-kJDbbIj/LFdcApRvjMenFDQZlsyU/_ddqHfRv5fyC9NhJ_E-p/7D4SZnYnAMBz-kJDbbIj "-extld=zig cc -target x86_64-macos" /home/ossi/.cache/go-build/d6/d63e39aa9f801811477c46cacd57130c2f575c58cb4eacb46322a63f04a4cbb6-d
/usr/lib/go/pkg/tool/linux_amd64/buildid -w $WORK/b001/exe/a.out.a # internal
# $WORK/b001/_cgo_install.h not created
cp $WORK/b001/exe/a.out.a test.a
rm -rf $WORK/b001/
$ zig version
0.14.0-dev.367+a57479afc
$ GOOS=darwin GOARCH=amd64 CC='zig cc -target x86_64-macos' CGO_ENABLED=1 go build -buildmode c-archive -x
WORK=/tmp/go-build300805020
mkdir -p $WORK/b046/
cd /usr/lib/go/src/runtime/cgo
TERM='dumb' CGO_LDFLAGS='"-O2" "-g" "-lpthread"' /usr/lib/go/pkg/tool/linux_amd64/cgo -objdir $WORK/b046/ -importpath runtime/cgo -import_runtime_cgo=false -import_syscall=false -exportheader=$WORK/b046/_cgo_install.h -- -I $WORK/b046/ -O2 -g -Wall -Werror -fno-stack-protector ./cgo.go
# runtime/cgo
error: unable to create compilation: AccessDenied

I am using go 1.22.4:

$ go version
go version go1.22.4 linux/amd64
ezekg commented 1 week ago

Did you solve this, @ostcar? Also hitting this issue with Zig v0.14.0-dev.1713+f99097e68 when cross-compiling CGO for Darwin on Linux. Currently fails for both x86_64 and aarch64 with an AccessDenied error.

Source: https://github.com/keygen-sh/keygen-relay

When attempting to build for Darwin:

DEBUG=1 make build-darwin-amd64

Which runs the following:

CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC="zig cc -target x86_64-macos" go build -v -x -ldflags "-s -w -X github.com/keygen-sh/keygen-relay/cli.Version=1.0.0-beta.1" -o dist/relay-darwin-amd64-1.0.0-beta.1 ./cmd/relay
WORK=/tmp/go-build1080282355
cd /home/$USER/code/keygen/relay
git status --porcelain
cd /home/$USER/code/keygen/relay
git -c log.showsignature=false log -1 --format=%H:%ct
github.com/mattn/go-sqlite3
mkdir -p $WORK/b205/
cd /home/$USER/go/pkg/mod/github.com/mattn/go-sqlite3@v1.14.23
TERM='dumb' CGO_LDFLAGS='' /usr/local/go/pkg/tool/linux_amd64/cgo -objdir $WORK/b205/ -importpath github.com/mattn/go-sqlite3 "-ldflags=\"-O2\" \"-g\"" -- -I $WORK/b205/ -O2 -g -std=gnu99 -DSQLITE_ENABLE_RTREE -DSQLITE_THREADSAFE=1 -DHAVE_USLEEP=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_TRACE_SIZE_LIMIT=15 -DSQLITE_OMIT_DEPRECATED -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT -Wno-deprecated-declarations -I/home/$USER/go/pkg/mod/github.com/mattn/go-sqlite3@v1.14.23 ./backup.go ./callback.go ./error.go ./sqlite3.go ./sqlite3_context.go ./sqlite3_load_extension.go ./sqlite3_opt_serialize.go ./sqlite3_opt_userauth_omit.go ./sqlite3_other.go ./sqlite3_type.go
# github.com/mattn/go-sqlite3
error: unable to create compilation: AccessDenied
make: *** [Makefile:44: build-darwin-amd64] Error 1

Running with strace, here's the relevant end of trace:

rlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, {rlim_cur=1024*1024, rlim_max=1024*1024}, NULL) = 0
openat(3, "h", O_RDONLY|O_LARGEFILE|O_CLOEXEC|O_PATH|O_DIRECTORY) = 5
openat(3, "o/5a1da8e1ce0be154e933f4d18a85e025", O_RDONLY|O_LARGEFILE|O_CLOEXEC|O_PATH|O_DIRECTORY) = -1 ENOENT (No such file or directory)
mkdirat(3, "o/5a1da8e1ce0be154e933f4d18a85e025", 0755) = 0
openat(3, "o/5a1da8e1ce0be154e933f4d18a85e025", O_RDONLY|O_LARGEFILE|O_CLOEXEC|O_PATH|O_DIRECTORY) = 7
openat(AT_FDCWD, "/usr/local/lib/zig/libc/darwin/SDKSettings.json", O_RDONLY|O_NOCTTY|O_LARGEFILE|O_CLOEXEC) = 8
statx(8, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_TYPE|STATX_MODE|STATX_ATIME|STATX_MTIME|STATX_CTIME, {stx_mask=STATX_BASIC_STATS|0x1000, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=30, ...}) = 0
mmap(NULL, 28672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5dc9aa8000
read(8, "{\"MinimalDisplayName\":\"14.0\"}\n", 5889) = 30
read(8, "", 5859)                       = 0
close(8)                                = 0
munmap(0x7f5dc9aa8000, 28672)           = 0
openat(AT_FDCWD, "cgo-gcc-input-1943159131.o", O_RDWR|O_CREAT|O_TRUNC|O_LARGEFILE|O_CLOEXEC, 0666) = -1 EACCES (Permission denied)
close(7)                                = 0
close(5)                                = 0
write(2, "error: unable to create compilat"..., 37) = 37
write(2, "AccessDenied", 12)            = 12
write(2, "\n", 1)                       = 1
munmap(0x7f5dd9b01000, 4096)            = 0
munmap(0x7f5dd9b15000, 4096)            = 0
munmap(0x7f5dd9afa000, 4096)            = 0
munmap(0x7f5dd9b21000, 8192)            = 0
exit_group(1)                           = ?
+++ exited with 1 +++

Environment info:

uname -a
# => Linux $USER 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
zig version
# => 0.14.0-dev.1713+f99097e68
go version
# => go version go1.23.2 linux/amd64

lmk if I can provide better info.

ostcar commented 1 week ago

No, I could not fix this. But its good to know, that it is not only me 😊