-
Notifications
You must be signed in to change notification settings - Fork 1.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
Document how to set environment variables in subprocesses #1002
Comments
Reading through that discussion, it seems that environment variables aren't supported in Ninja because It's really simple to set the environment inherited by a process on all platforms, so I'd like to understand what the blocker is here. Cheers! |
FWIW, we would really make good use of this feature in Meson: mesonbuild/meson#266, mesonbuild/meson#384, etc. |
Would the project be interested in a PR that implements this? It's a troublesome blocker downstream for https://github.com/mesonbuild/meson/ since we have to add wrapper scripts for any command that needs environment variables set, which is slowly turning out to be quite a few. Even Makefiles and Visual Studio project files support this, so Ninja stands out in not supporting this. :) We'd be happy to implement this though if there is interest in having this feature in Ninja. |
On POSIXy platforms, you can do
or
Is that not enough for you? Most commands shouldn't need env vars, and generally supporting less stuff keeps ninja simple. |
Yes, that part is documented, but Meson is a cross-platform build system (meant to have feature-parity across all supported platforms) and we currently have to use Python script wrappers whenever we need to set environment variables or have arguments with special characters (especially newlines). At first, we also thought that setting env vars is a niche use-case and pushed back when users asked for it, but a surprisingly large number of people need it. For instance, gobject-introspection in GNOME requires you to set The Python script workaround is ok, but invoking the python interpreter for each command really slows things down sometimes. |
Maybe gobject-introspection could accept those via command line args instead? (In my experience, builds that rely on env vars instead of flags tend to be much more vulnerable to devs screwing up their local env, etc.) MSVC's cl.exe requires a few env vars to find includes and whatnot; for that ninja has But using python wrappers for the rare, "needs to be flexible" case and making the common commands work without reliance on the env seems like the best approach to me. |
I think I've run into this issue. I'm trying to build a FIPS executable on window, and need to follow these directions: https://www.openssl.org/docs/fips/UserGuide-2.0.pdf, section 5.3.2:
Even though FIPS_CC is defined in my environment, it looks like ninja is not passing the env to the child process ( |
Another use-case for this is setting As another datapoint, cmake came across this use-case so much that they have a C wrapper for it which sets the environment and then calls the process. They need it anyway for their make backend, but ninja-only build systems would greatly benefit from this feature. |
I'm not really sure what this bug is discussing anymore, since it looks like it was originally about updating the docs. :) For On Windows we have |
Kconfiglib has a hard
From: https://github.com/ulfalizer/Kconfiglib/tree/424d0d38e7be15c5#overview
|
I think I might have hit this in #1997 where Meson calls Ninja, Ninja calls Meson back, but without inherited environment variables and everything falls apart because of that. |
https://mesonbuild.com/Reference-manual.html#run_target meson has various cases where it runs commands which are "wrapped due to env", and sometimes, like for run_target(), this is because the created build rule has automatic functionality where it communicates namespaced
Given any environment variable set in build.ninja would be generated, statically coded, and always there (no ifs ands or buts), it seems unlikely to have real life failure cases. It doesn't matter how you screw up your env, because your env is always ignored and overridden by build.ninja |
So… Doesn't this feature belong to the goals of Ninja project? The documentation says, quoting:
From reading the discussion, supporting this feature will improve build speed in many cases. So, is there any reason not to support it? |
I am not sure is it for my use case: run unittest of llvm with qemu-user. Background:
While
It means that |
See discussion on
https://groups.google.com/d/topic/ninja-build/ZGZ2Ewxsxaw/discussion
and previous thread linked there.
The text was updated successfully, but these errors were encountered: