Skip to content

feat: support toolchains building zig from source#646

Open
cerisier wants to merge 7 commits intoaherrmann:mainfrom
cerisier:from-source
Open

feat: support toolchains building zig from source#646
cerisier wants to merge 7 commits intoaherrmann:mainfrom
cerisier:from-source

Conversation

@cerisier
Copy link
Copy Markdown
Contributor

@cerisier cerisier commented May 7, 2026

As explained in #644

This PR makes it possible to build zig from source as part of the toolchain.
The way it works is by allowing end users to define their own:

zig_toolchain(
    name = "zig_from_source",
    zig_cache = "/var/tmp/zig-cache",
    zig_exe = "@zig//:zig",
    zig_h = "@zig//:zig_h",
    zig_lib = "@zig//:lib_dir",
    zig_version = "0.16.0",
)

toolchain(
    name = "zig-source-toolchain"
    target_settings = [
        "@rules_zig//zig/config/bootstrapped:bootstrap_enabled",
    ],
    toolchain = ":zig_from_source",
    toolchain_type = "@rules_zig//zig:toolchain_type",
    target_compatible_with = [...],
)

and passing a new build flat --@rules_zig//zig/settings:bootstrapped=True.

This setting is used in a rule transition for zig_toolchain, setting bootstrapped=False so that all dependencies of zig_toolchain if they are zig targets, do not resolve the same zig_from_source toolchain but the prebuilt toolchain which doesn't have the bootstrapped target_settings.


However, this PR currently breaks compatibility with path-based non hermetic zig installations.

Supporting local installation is very easy with this setup if we use new_local_repository with symlinks but I remember your objections wrt windows.

I wonder if there is a way to somehow split the logic entirely so that we don't end up with 1 toolchain API bent to support 2 conflicting use case.

Another argument to keep passing File around in the nominal case is to support path mapping which prohibits passing .path to actions.

steeve and others added 7 commits May 7, 2026 13:15
    * zig_asm

    * Simplify zig_toolchain

    Require labels as cfg exec
    Symlinking Zig exe and libs for zig local toolchain
    Stop forwarding exe paths and use file everywhere
    Explicit dependency on zig.h
    Use dirname of zig.h file for lib paths

    * source directory

    * do not use .path for zig_lib

    * zig_exe_file -> zig_exe

    * no _single_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants