zig
zig copied to clipboard
Crosscompile CGO using zig 0.12 or newer
Zig Version
0.14.0-dev.367+a57479afc
Steps to Reproduce and Observed Behavior
- Create a go sourcefile that uses cgo. For example:
package main
import "C"
import "fmt"
func main() {
fmt.Println(C.int(10))
}
-
Create a go.mod file with
go mod init test
-
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.