Zig: Implement standard library path search

Created on 10 Sep 2017  路  6Comments  路  Source: ziglang/zig

If the command line --zig-std-dir is given, use that path and assert an error if the path doesn't exist. When the option is not given, check if the standard library lives in a path relative to where the zig executable is installed. If it does not exist there, then look for the standard library using a hardcoded value that was provided when zig was compiled. This could be some default path or could have been customized for a specific zig build.

enhancement

Most helpful comment

This should help us provide a static zig.exe for windows that works with no hassle. I'm thinking just a .zip file that you extract to a directory, and viola. Zig compiler.

All 6 comments

This should help us provide a static zig.exe for windows that works with no hassle. I'm thinking just a .zip file that you extract to a directory, and viola. Zig compiler.

Ooh, nice!

Could you extend that to multiple directories? Either via multiple --zig-std-dir argument pairs or via some separator and multiple directories in the argument. One reason to do it with multiple --zig-std-dir argument pairs would be that then you do not need to try to match different OS's separators to keep the paths separate:

zig --zig-std-dir c:\users\kyle\myZigInstall --zig-std-dir c:\programs\zigInstall

If this is to point the compiler at the library, would it make more sense to use --zig-std-lib?

Will the compiler read environment variables? I.e. set ZIG_STD_DIR to get the same behavior as the original proposal?

@kyle-github What's the purpose of multiple directories?

If I want to use a standard install on the system (read-only directory) and still install code in my own home directory, then I will want to search multiple paths. With many languages, some extensions/libraries are installed at the system level and others are local. The same things happens when searching for binary libraries.

The proposed solution supports up to 2 paths, the relative path and the shared global path, what would be the reason for adding more?

For the sake of clarity I'm going to include an example of how this might work. Say zig.exe is installed here:

c:\myzigversion0.1build-a819fec91\zig.exe

The idea is that each instance of zig.exe will always have an instance of the standard library living relative to it. The exact path where it lives is up to Andrew/Josh, but let's say it lives here:

c:\myzigversion0.1build-a819fec91\zig\std

So as long as the standard library path is not overriden with --zig-std-dir, then it should always find the standard library in it's relative path.

With this new methodology of each compiler having it's own instance of the standard library, there doesn't seem to be much use for even having a single shared global standard library let alone have multiple versions of the standard library living on the system. And for the purposes of temporarily using a different version of the standard library, the single --zig-std-dir command line option serves this purpose.

Hmm. OK, I see your reasoning. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bronze1man picture bronze1man  路  3Comments

fengb picture fengb  路  3Comments

komuw picture komuw  路  3Comments

jorangreef picture jorangreef  路  3Comments

andrewrk picture andrewrk  路  3Comments