zig icon indicating copy to clipboard operation
zig copied to clipboard

Add ZIG_SYSROOT env var

Open RossComputerGuy opened this issue 2 years ago • 6 comments

Allows Zig's sysroot to be set by $ZIG_SYSROOT env var, this is useful for wrapper scripts.

RossComputerGuy avatar Feb 23 '24 01:02 RossComputerGuy

os.getenv isnt cross platform

it looks like you should add it to here https://github.com/ziglang/zig/blob/8802ec583b376101ee7fcb0a64cf937b90dc6130/src/introspect.zig#L147-L155 then you can do EnvVar.ZIG_SYSROOT.isSet() or get() in main. for the build runner it looks like graph has an env map, i assume you should use that https://github.com/ziglang/zig/blob/8802ec583b376101ee7fcb0a64cf937b90dc6130/lib/build_runner.zig#L71

xdBronch avatar Feb 23 '24 01:02 xdBronch

@xdBronch Thanks for letting me know, I'm not a Windows dev so I didn't know that would be a problem. I've adjusted the code so it uses the cross platform way to get the env var.

RossComputerGuy avatar Feb 23 '24 01:02 RossComputerGuy

I see you updated your comment, I've now changed it to use the env map and the env var enum.

RossComputerGuy avatar Feb 23 '24 01:02 RossComputerGuy

yeah my bad, realized its not terribly useful to just say dont use something

xdBronch avatar Feb 23 '24 01:02 xdBronch

Do we actually need this at all? Would it not be better to promote having libc.txt setup instead? Zig should parse libc.txt inferring sysroot and all relevant system include/lib dirs automatically. Unless I am missing the point of your change, then you could re-use ZIG_LIBC env var too https://github.com/ziglang/zig/blob/5005c6243a37f7fc9f23dae298b0dafa085fa044/src/main.zig#L983.

kubkon avatar Mar 20 '24 21:03 kubkon

@kubkon I mainly did it this way because I needed to only change the system root but didn't want to write out an entire libc config file.

RossComputerGuy avatar Mar 20 '24 21:03 RossComputerGuy