zig cc: Respect Clang's -static and -dynamic flags.

Before:

    ❯ zig cc main.c -target x86_64-linux-musl && musl-ldd ./a.out
    musl-ldd: ./a.out: Not a valid dynamic program
    ❯ zig cc main.c -target x86_64-linux-musl -static && musl-ldd ./a.out
    musl-ldd: ./a.out: Not a valid dynamic program
    ❯ zig cc main.c -target x86_64-linux-musl -dynamic && musl-ldd ./a.out
    musl-ldd: ./a.out: Not a valid dynamic program

After:

    ❯ zig cc main.c -target x86_64-linux-musl && musl-ldd ./a.out
    musl-ldd: ./a.out: Not a valid dynamic program
    ❯ zig cc main.c -target x86_64-linux-musl -static && musl-ldd ./a.out
    musl-ldd: ./a.out: Not a valid dynamic program
    ❯ zig cc main.c -target x86_64-linux-musl -dynamic && musl-ldd ./a.out
            /lib/ld-musl-x86_64.so.1 (0x72c10019e000)
            libc.so => /lib/ld-musl-x86_64.so.1 (0x72c10019e000)

Closes #11909.
This commit is contained in:
Alex Rønne Petersen
2025-04-14 21:01:25 +02:00
parent 715984340b
commit 6a8228603c
3 changed files with 29 additions and 2 deletions

View File

@@ -572,6 +572,14 @@ const known_options = [_]KnownOpt{
.name = "rtlib=",
.ident = "rtlib",
},
.{
.name = "static",
.ident = "static",
},
.{
.name = "dynamic",
.ident = "dynamic",
},
};
const blacklisted_options = [_][]const u8{};