-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make the CLI support depending on system headers and libraries (include and lib search paths) #2041
Comments
If I do
|
this was never actually used anyway
This works:
I still liked the old behaviour where I didn't need to specify the paths verbosely |
This is an important topic moving forward. I recognize that for some use cases, this is a step backwards in convenience. Whereas before, However, depending on system headers and libraries is an important use case, as long as it's intentional. Note: I see a few different directions this could take, and I'm not sure which one is best yet.
|
Assuming the zig package manager works well, then i think the third bullet is best; make it explicit when you're depending on specific system dependencies. And projects that want to be friendly to the zig package manager would be encouraged to never do that. EDIT: i take it back. i don't think i understand the usecase for this. i need to do more research. |
Boooooo. How in the world is this better than the old behaviour? I don't see how having to hard-code the path of a header file that includes the architechture name is "system-independent builds". I still have no idea how to figure out the correct command-line arguments from a build script anyway. If that's not possible from within a |
@Akuli did you see the first bullet point? I'm pretty sure that's exactly what you want, no? |
Yes, but I don't understand how the change gives more "system-independent builds". |
The thing that got harder to do (and is an open issue because I recognize that it is a problem) is depend on your system's gmp library. So the fact that you're getting an error for trying to do a system-dependent build makes it harder to do on accident. You're getting an error for the thing that is preventing your code from working on more systems. This will make a lot more sense once we have a working package manager, but given that we don't have that yet, I think it probably does make sense to do the first bullet point for the 0.4.0 release. It doesn't make sense to deprecate the "old way" of doing things until the new way is available. |
Yes, the first bullet point would be nice. |
Can someone ELI5 how relying on the system's gmp.h is "system-dependent"? If I write something like "install GMP with your favorite package manager" to my README, I expect everyone to install it before attempting to compile my code. As far as I can tell, using the system's package manager is a very cross-platform way to install C libraries. |
Here are some things to consider:
These are all considerations that apply to depending on system headers and libraries, and, importantly, they do not apply to zig package manager packages, or to source files that you bundle with your own source. |
Thanks for patiently explaining all the things to me. Now I see why it's better to specify With the current zig, how do I write a |
Another thought: Will projects like GMP be in zig's package manager whenever that will be ready? Otherwise it's useless for this, and instead of solving the problems with system-wide installed dependencies I would need system-wide dependencies and some extra gibberish to worry about. |
With current Zig, I hope you can make do temporarily with this workaround where you specify some hard coded search paths. You can use Line 161 in 83b7952
Line 135 in 83b7952
I don't think that should be necessary - worst case scenario you could have build.zig do whatever your shell script was going to do. I recognize that the hard coded path workaround is an issue, but do you think it could be an acceptable workaround for a week or two until I resolve this issue?
Yes absolutely. GMP is a great candidate to be a zig package. |
I was talking about something like this: // this is build-template.zig
...
lib_exe_obj.addIncludeDir("INCLUDEDIR");
lib_exe_obj.addLibPath("LIBPATH");
... #!/bin/bash
# this is build.sh
includedir="$1"
libpath="$2"
cp build-template.zig build.zig
sed -i "s:INCLUDEDIR:$includedir:" build.zig
sed -i "s:LIBPATH:$libpath:" build.zig
zig build Now that I think about this a bit more, I could use environment variables instead of this. Maybe I'll do that. |
it looks like your In general, anything you can do in a bash script you can also do in pure zig[1], so there should never[1] be a usecase for generating zig code. [1] To be pedantic, there are cases for generating zig code, but they are very specific such as generating struct definitions. This is an unsolved issue in zig's design. See the "refiy" discussions for more info on that one specifically. |
I tried to ask about this earlier:
Nobody told me how to do it. |
Here's an example of adding build options: Line 68 in a909efa
You can see how to specify them with |
This looks nice. Thanks! |
In the above commit, I made it so that if you call I'm going to leave this issue open for reconsideration in the 0.5.0 milestone. Once we have the zig package manager I think it will be worth revisiting what is the workflow for both the use cases of trying to depend on system things, and trying to avoid system dependencies. It also may make sense to move this logic to the Zig CLI, or maybe make the way that libc is specified special. I want to leave this open and think about it for a while. But for now, if you use zig build then Note to self: remember to double check or add a test for a transitive dependency on system paths. For example if one artifact links a system library, and then another one links the first artifact. |
I think it would be valuable to expose the ability to search system include paths from the CLI. I'm happy with the non-default searching as outlined in your previous comment regarding the I've had to write some trivial build scripts already for a few cases which is mildly annoying. I personally can make do, but I imagine that this would be a moderately common barrier for newer users or those which want to share a quick example which happens to utilize system c libraries. |
I think |
IMO |
Sure, but there's already a relatively standard flag |
I think this can be solved in the stage1/stage2 hybrid, the same way that translate-c is self-hosted. The logic can be moved from the build system implementation into the self-hosted compiler, and then exposed to the stage1 compiler. This is related to #3089. |
On my system,
@cImport(@cInclude("stdio.h"))
works, but@cImport(@cInclude("gmp.h"))
doesn't.gmp.h
is in/usr/include/x86_64-linux-gnu
, andstdio.h
is in/usr/include
. I'm running a simple test file withzig test filename.zig --library gmp --library c
:This worked in
0.3.0+9c5852aa
, but is broken in0.3.0+0a8a7a57
. On this system, zig is cloned to~/sourcestuff/zig
and built there, thenbin
andlib
are copied to~/zig/
(~/zig/bin
is in$PATH
).The text was updated successfully, but these errors were encountered: