1
hermetic_cc_toolchain/README.md

42 lines
1.5 KiB
Markdown
Raw Normal View History

# Bazel zig cc toolchain for Go
2021-04-10 01:05:01 +03:00
2021-06-07 23:23:21 +03:00
This is a prototype zig-cc toolchain that can compile cgo programs with these c
libraries:
2021-04-10 01:05:01 +03:00
- glibc 2.19
2021-06-07 23:23:21 +03:00
- musl
2021-04-10 01:05:01 +03:00
# Testing
2021-04-10 01:05:01 +03:00
2021-06-07 23:22:51 +03:00
## cgo + glibc 2.19
2021-04-10 01:05:01 +03:00
```
$ bazel build //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
2021-04-10 01:05:01 +03:00
```
2021-06-07 23:22:51 +03:00
## cgo + musl
2021-04-10 01:05:01 +03:00
```
$ bazel build --platforms @com_github_ziglang_zig//:platform_linux-x86_64-musl :gomusl
...
$ file ../bazel-out/k8-fastbuild-ST-d17813c235ce/bin/test/gomusl_/gomusl
../bazel-out/k8-fastbuild-ST-d17813c235ce/bin/test/gomusl_/gomusl: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=redacted, with debug_info, not stripped
$ ../bazel-out/k8-fastbuild-ST-d17813c235ce/bin/test/gomusl_/gomusl
hello, world
2021-04-10 01:05:01 +03:00
```
2021-04-10 02:58:05 +03:00
2021-06-07 23:22:51 +03:00
## Transient docker environment
2021-04-10 02:58:05 +03:00
```
2021-06-07 23:22:51 +03:00
$ docker run -ti --rm -v $(pwd):/x -w /x debian:buster-slim
# apt update && apt install curl ca-certificates -y && curl -L https://github.com/bazelbuild/bazelisk/releases/download/v1.7.5/bazelisk-linux-amd64 > /usr/local/bin/bazel && chmod +x /usr/local/bin/bazel
2021-04-10 02:58:05 +03:00
# export CC=/usr/bin/false
2021-06-07 23:22:51 +03:00
# bazel run --platforms @com_github_ziglang_zig//:platform_linux-x86_64-musl //test:gomusl
2021-06-08 05:04:10 +03:00
# bazel run --platforms @com_github_ziglang_zig//:platform_linux-x86_64-gnu //test:gognu
```