Skip to content

Support linking using cc_common.link #519

@cerisier

Description

@cerisier

Currently, tests, executables and shared libraries are linked using zig.

However, there are scenarios where it is useful to defer the link using the linker configured by rules_cc:

  1. it's not possible to override the linker using zig build-* (-flld is lld only and is ignored on macos)
  2. SPEED, on macos we go from 40s to 8s linking
  3. control, not all options are supported and some are even swallowed (zig cc silently ignores -fuse-ld= option ziglang/zig#18357)

Proposed approach

Introduce a linkmode string_flag with 2 possible values ["zig" (default), "cc"] and use that in zig_build_impl to perform the linking accordingly.

When linkmode = "cc", we always produce a static library and use cc_common.link to perform the link, letting rules_cc deal with linker_inputs from transitive C deps.

When zig is used, nothing changes, zig is used to produce the final artifact and linker inputs of transitive C deps are collected and added to the compiler CLI arguments just like it is the case today.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions