Skip to content

feat(cli): add -C link-sysroot option and custom linker validation#311

Merged
LunaStev merged 1 commit into
wavefnd:masterfrom
LunaStev:feat/(cli)-add-`-C-link-sysroot`-option-and-custom-linker-validation
Apr 1, 2026
Merged

feat(cli): add -C link-sysroot option and custom linker validation#311
LunaStev merged 1 commit into
wavefnd:masterfrom
LunaStev:feat/(cli)-add-`-C-link-sysroot`-option-and-custom-linker-validation

Conversation

@LunaStev
Copy link
Copy Markdown
Member

@LunaStev LunaStev commented Apr 1, 2026

This PR enhances the Wave compiler's CLI by introducing fine-grained control over the sysroot during the linking stage. It adds the -C link-sysroot=<path> option and implements a safety validation check to prevent common configuration errors when using custom linkers alongside general sysroots.

Key Changes

1. New Linker Option: -C link-sysroot

  • Added -C link-sysroot=<path> to the codegen specification parser.
  • This allows developers to explicitly specify which sysroot the linker should use, which may differ from the compiler's general sysroot in complex cross-compilation environments.

2. Custom Linker Safety Validation

  • Problem: Previously, specifying a general --sysroot would apply to the compilation stage, but might be ignored by a custom linker specified via -C linker. This led to confusing "file not found" or "incompatible library" errors during the final link phase.
  • Solution: Updated validate_build_request to enforce a new safety rule: if both a custom linker and a general sysroot are provided, the user must now explicitly provide a -C link-sysroot. This ensures the developer is consciously aware of where the linker is searching for libraries.

3. Argument Management Helpers

  • Introduced a suite of helper functions to manage internal linker arguments safely:
    • is_link_sysroot_arg: Identifies sysroot-related strings.
    • has_explicit_link_sysroot_arg: Checks if the sysroot has already been set in the build plan.
    • set_link_sysroot_arg: Safely updates or appends the sysroot argument while avoiding duplication.

4. Documentation

  • Updated the CLI help output (wavec --help) to include and describe the new -C link-sysroot option.

Rationale

In systems programming and OS development, the compiler's view of the "system" (headers/core logic) and the linker's view (standard libraries/start files) can sometimes diverge. By requiring explicit link sysroots when a custom linker is involved, Wave prevents "silent" linking failures where the compiler assumes the linker inherited the general sysroot.

Example Usage

Explicitly providing a link sysroot for a custom cross-linker:

wavec build main.wave \
    --sysroot /path/to/compiled/headers \
    -C linker=aarch64-linux-gnu-ld \
    -C link-sysroot=/path/to/target/libs

This commit introduces a new `-C link-sysroot=<path>` option to explicitly pass a sysroot argument to the linking stage.

It also adds a safety validation check to the build request: when both a custom linker (`-C linker=...`) and a general sysroot (`--sysroot=...`) are specified, the CLI now requires the user to explicitly define the linker's sysroot. This prevents confusing build failures where the general sysroot is applied only to the compile stage but ignored during the link stage by the custom linker.

[Details]
- Added `-C link-sysroot=<path>` to `parse_llvm_codegen_spec`.
- Added validation in `validate_build_request` to enforce explicit link sysroot when using a custom linker alongside a general sysroot.
- Added helper functions (`is_link_sysroot_arg`, `has_explicit_link_sysroot_arg`, `set_link_sysroot_arg`) to safely manage, check, and deduplicate sysroot link arguments.
- Updated the CLI help output (`print_help`) to document the new option.

Signed-off-by: LunaStev <luna@lunastev.org>
@LunaStev LunaStev merged commit d48e820 into wavefnd:master Apr 1, 2026
2 checks passed
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.

1 participant