~andrewrk/ziglang

[ANN] bazel-zig-cc generally usable

Details
Message ID
<20210811104907.qahogqbdjs4trihn@mtpad.i.jakstys.lt>
DKIM signature
missing
Download raw message
Hi folks,

I am announcing bazel-zig-cc[1]: a C++ toolchain for Bazel projects
based on the venerable zig c++. It is generally usable: to register a
default C++ toolchain for x86_64 linux target, add a couple of lines[2]
to the WORKSPACE.

# Usage

Add these lines to your WORKSPACE. With this, Bazel targets that invoke
a C++ compiler will use `zig c++`.

    BAZEL_ZIG_CC_VERSION = "0.3"

    http_archive(
        name = "bazel-zig-cc",
        sha256 = "e78a9930daa40c47fa67de7e371851452d3eedbb5f56d2904d46e2784888e21e",
        strip_prefix = "bazel-zig-cc-{}".format(BAZEL_ZIG_CC_VERSION),
        urls = ["https://git.sr.ht/~motiejus/bazel-zig-cc/archive/{}.tar.gz".format(BAZEL_ZIG_CC_VERSION)],
    )

    load("@bazel-zig-cc//toolchain:defs.bzl", zig_register_toolchains = "register_toolchains")

    zig_register_toolchains(register = [
        "x86_64-linux-gnu.2.28",
        "x86_64-macos-gnu",
    ])

Much more in the Usage[2] section of the README.

# Known Issues

The only High-severity issue is worth elaborating: `zig c++` may fail
when invoked in parallel (which Bazel does a lot). Until the issue is
resolved[3], we serialize all `zig c++` commands, which, unsurprisingly,
slows down the build by the number of cores you have, but avoids a
compilation failure.

If you decide to onboard, it is worthwhile to read the minor ones
too[4].

# FAQ

Q: Will this ever gain a `zig` target to compile Zig programs?
A: I am not planning to add it (I don't have an immediate need), but am
   open to a contribution.

Q: Will there be breaking changes?
A: Definitely! However, I am open to communicating these changes with
   anyone who decides to use it.

Regards,
Motiejus

[1]: https://git.sr.ht/~motiejus/bazel-zig-cc
[2]: https://git.sr.ht/~motiejus/bazel-zig-cc#usage
[3]: https://github.com/ziglang/zig/issues/9431
[4]: https://git.sr.ht/~motiejus/bazel-zig-cc#known-issues
Reply to thread Export thread (mbox)