marler8997/zigup

Add a symbolic link to the files of the default compiler

Opened this issue · 6 comments

I'm using Zig master to build my C projects.

One of the tools I use requires the location of the standard library to function. As I use master, this location changes each time I update the compiler.

If zigup created a symbolic link to the files, as well as the compiler itself, I could simply pass the symbolic link.

zig\files > zig\<default-version>\files

I appreciate this is likely a niche use case and I can create a batch file to handle it myself, but thought I'd double check.

This does seem pretty niche to me. Since zigup modifies a symlink that is shared by the whole user session (any process with the same PATH directory to zig), it would seem odd to me that another unrelated process could update the zig compiler and break the build of another project.

If it were me I might consider resolving the zig std library path to a real path that remains mostly immutable (maybe copy it to my project as well?) but I can't say for sure without seeing the project myself.

The processes are related; Updating the Zig compiler should impact both of them equally.

The project is just any C project. I build them all with Zig master atm.

The tool compiles, runs, and debugs my code live as I'm working on it. But to do that, it needs the location of the C standard library to link to. It doesn't modify any files in the project, or in Zig.

Is this a public project that you can link me to? If not, is this something that could use zig env | jq .lib_dir to get the path to zig's libraries? Also I'm not sure what paths you need exactly, if you need the libraries to link against wouldn't that be paths in the global zig cache directory rather than the path to the toolchain? I'd like to help more but I think I'm missing some information.

All of my C projects are based on my C template.

The tool, WhiteBox, has an input box for the flags you want to pass to the JIT compiler:

-resource-dir "C:\Users\Fletcher\Programs\bin\whitebox_v0.96.2\clang\11.0.0"
-isystem "C:\Users\Fletcher\Programs\bin\whitebox_v0.96.2\clang\11.0.0\include"
-fdebug-compilation-dir "C:\Users\Fletcher\Programs\bin\whitebox_v0.96.2"
-isystem "C:\Users\Fletcher\Programs\bin\zig\0.10.0-dev.4198+5e0d8a435\files\lib\libc\include\any-windows-any"

The last flag is the one in question. WhiteBox requires the location of the C standard library headers so it can find stdio.h, etc. I want to pass it a value that I don't need to manually update each time I update the Zig compiler.

I didn't realise zig env | jq .lib_dir was a thing, but I don't think I can pass that as an argument. The closest I can get is echo-ing the correct value in the command prompt.

for /F "usebackq delims=" %A in (`zig env | jq -j .lib_dir`) do echo "%A\libc\include\any-windows-any"

Thanks for trying to help, despite it being a niche use case. And I apologise for mixing up terminology in the previous message.

If nothing else comes from this, I at least have a cleaner solution than before. I can write a batch script that creates the right path using zig env, exports it, and opens WhiteBox.

Are all of your C projects "Windows Only"? The specific include paths that you'll need from Zig will depend on your target and are an "implementation detail" that could change in the future. It's a little unclear to my why you would need to specify the C include path to zig, I'm not sure how zig is being invoked here? Normally that should be added so long as your linking to libc through -lc.

My projects use Zig to build, the tool doesn't. I think it uses a builtin version of Clang. It needs the C include path otherwise it can't find stdio.h, etc. and won't compile.

With your suggestion of zig env, this is how I currently launch the tool:

@echo off

set link="C:\Users\Fletcher\Programs\bin\zig\lib"

for /F "usebackq delims=" %%A in (`zig env ^| jq -j .lib_dir`) do (
	if exist "%link%\" (
		rd %link%
	)

	mklink /d %link% "%%A"
)

start launch_whitebox.exe

And then I provide the flag:

-isystem "C:\Users\Fletcher\Programs\bin\zig\lib\libc\include\any-windows-any"

This is significantly more future-proof than my previous solution, which grabbed the version from the "master" file and used that to create the target path. Thanks!

However, if I download Zig from the website and install it manually, I'd be able to reach the lib_dir path without requiring zig env or the batch file.