update README
This commit is contained in:
parent
5511138adf
commit
30cfc86e9a
63
README.md
63
README.md
@ -2,40 +2,27 @@
|
|||||||
|
|
||||||
# Bazel zig cc toolchain for Go
|
# Bazel zig cc toolchain for Go
|
||||||
|
|
||||||
This is a prototype zig-cc toolchain that can compile cgo programs with these c
|
This is a prototype zig-cc toolchain that can cross-compile cgo programs to these os/archs:
|
||||||
libraries:
|
|
||||||
|
|
||||||
- glibc 2.19
|
- x86_64-linux-musl
|
||||||
- musl
|
- x86_64-linux-gnu.2.19
|
||||||
|
- aarch-linux-musl
|
||||||
|
- aarch-linux-gnu.2.19
|
||||||
|
- x86_64-macos
|
||||||
|
- aarch64-macos
|
||||||
|
|
||||||
glibc 2.19 is the default. That means, glibc 2.19 toolchain is registered with
|
Convenient way is still being researched (see Known Issues below).
|
||||||
these basic constraints:
|
|
||||||
|
|
||||||
```
|
|
||||||
[
|
|
||||||
"@platforms//os:linux",
|
|
||||||
"@platforms//cpu:x86_64",
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
# Testing
|
# Testing
|
||||||
|
|
||||||
## linux cgo + glibc 2.19
|
## linux cgo + glibc 2.19
|
||||||
|
|
||||||
Using the default toolchain:
|
Glibc toolchain is suffixed with `-gnu`:
|
||||||
|
|
||||||
```
|
|
||||||
$ bazel build --toolchain_resolution_debug=true //test:gognu
|
|
||||||
...
|
|
||||||
$ ../bazel-bin/test/gognu_/gognu
|
|
||||||
hello, world
|
|
||||||
$ file ../bazel-bin/test/gognu_/gognu
|
|
||||||
../bazel-bin/test/gognu_/gognu: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.0.0, Go BuildID=redacted, with debug_info, not stripped
|
|
||||||
```
|
|
||||||
|
|
||||||
Explicitly the toolchain explicitly `-gnu`:
|
|
||||||
```
|
```
|
||||||
$ bazel run --platforms @zig_sdk//:x86_64-linux-gnu //test:gognu
|
$ bazel run --platforms @zig_sdk//:x86_64-linux-gnu //test:gognu
|
||||||
|
$ file bazel-bin/test/gognu_/gognu
|
||||||
|
bazel-bin/test/gognu_/gognu: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.0.0, Go BuildID=redacted, with debug_info, not stripped
|
||||||
```
|
```
|
||||||
|
|
||||||
## linux cgo + musl
|
## linux cgo + musl
|
||||||
@ -49,13 +36,13 @@ $ ../bazel-out/k8-fastbuild-ST-d17813c235ce/bin/test/gomusl_/gomusl
|
|||||||
hello, world
|
hello, world
|
||||||
```
|
```
|
||||||
|
|
||||||
## macos cgo + gnu
|
## macos cgo
|
||||||
|
|
||||||
Does not work?
|
|
||||||
|
|
||||||
```
|
```
|
||||||
$ bazel build --platforms @zig_sdk//:x86_64-macos-musl //test:gognu
|
$ bazel build --platforms @zig_sdk//:x86_64-macos-gnu //test:gognu
|
||||||
...
|
...
|
||||||
|
$ file bazel-bin/test/gognu_/gognu
|
||||||
|
bazel-bin/test/gognu_/gognu: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Transient docker environment
|
## Transient docker environment
|
||||||
@ -69,20 +56,12 @@ $ docker run -ti --rm -v $(pwd):/x -w /x debian:buster-slim
|
|||||||
And run the `bazel build` commands above. Take a look at `.build.yml` and see
|
And run the `bazel build` commands above. Take a look at `.build.yml` and see
|
||||||
how CI does it.
|
how CI does it.
|
||||||
|
|
||||||
# Appendix: compiling manually
|
|
||||||
|
|
||||||
zcc
|
|
||||||
```
|
|
||||||
#!/bin/bash
|
|
||||||
exec zig cc -target x86_64-macos-gnu "$@"
|
|
||||||
```
|
|
||||||
|
|
||||||
Build:
|
|
||||||
```
|
|
||||||
GOOS=darwin GOARCH=amd64 CC=zcc go build -ldflags "-linkmode external -extldflags -static" hello.go
|
|
||||||
```
|
|
||||||
|
|
||||||
# Known Issues
|
# Known Issues
|
||||||
|
|
||||||
|
- [ziglang/zig #9139 zig c++ hanging when compiling golang for macos](https://github.com/ziglang/zig/issues/9139).
|
||||||
|
- [rules/go #2894 Per-arch_target linker flags #2894 ](https://github.com/bazelbuild/rules_go/issues/2894).
|
||||||
|
|
||||||
|
Closed issues:
|
||||||
|
|
||||||
- [golang/go #46644: cmd/link: with CC=zig: SIGSERV when cross-compiling to darwin/amd64](https://github.com/golang/go/issues/46644) (CLOSED)
|
- [golang/go #46644: cmd/link: with CC=zig: SIGSERV when cross-compiling to darwin/amd64](https://github.com/golang/go/issues/46644) (CLOSED)
|
||||||
- [ziglang/zig #9050 golang linker segfault](https://github.com/ziglang/zig/issues/9050)
|
- [ziglang/zig #9050 golang linker segfault](https://github.com/ziglang/zig/issues/9050) (CLOSED)
|
||||||
|
Loading…
Reference in New Issue
Block a user