-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Avoid depending on child process execution when not supported by host OS #10782
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a nit on can_spawn
else looking good.
Did you check what is still missing?
Any of translate-c, ar, dlltool, lib, ranlib ?
@@ -936,6 +936,12 @@ pub const can_execv = switch (builtin.os.tag) { | |||
else => true, | |||
}; | |||
|
|||
/// Tells whether spawning child processes is supported (e.g. via ChildProcess) | |||
pub const can_spawn = switch (builtin.os.tag) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will likely need to be extended to encompass other stuff, so add a TODO
for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that can_spawn
will still need to be updated to be correct for other targets? If so, more than happy to add the TODO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to make the TODO in a github issue rather than a comment, please :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Left you some review comments.
lib/std/child_process.zig
Outdated
return self.spawnPosix(); | ||
} else { | ||
unreachable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this spawn function should be untouched, or if you want to make the compile error clearer, put at the top of it:
if (!std.process.can_spawn) {
@compileError("the target operating system cannot spawn processes");
}
@@ -936,6 +936,12 @@ pub const can_execv = switch (builtin.os.tag) { | |||
else => true, | |||
}; | |||
|
|||
/// Tells whether spawning child processes is supported (e.g. via ChildProcess) | |||
pub const can_spawn = switch (builtin.os.tag) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to make the TODO in a github issue rather than a comment, please :-)
build.zig
Outdated
@@ -229,6 +229,11 @@ pub fn build(b: *Builder) !void { | |||
const version = if (opt_version_string) |version| version else v: { | |||
const version_string = b.fmt("{d}.{d}.{d}", .{ zig_version.major, zig_version.minor, zig_version.patch }); | |||
|
|||
// If we can't spawn a process for git, just trust the version string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we can't spawn a process for git, emit a fatal error here saying that it must be provided with -Dversion-string
.
src/main.zig
Outdated
@@ -4081,7 +4093,7 @@ extern "c" fn ZigClang_main(argc: c_int, argv: [*:null]?[*:0]u8) c_int; | |||
extern "c" fn ZigLlvmAr_main(argc: c_int, argv: [*:null]?[*:0]u8) c_int; | |||
|
|||
/// TODO https://github.com/ziglang/zig/issues/3257 | |||
fn punt_to_clang(arena: Allocator, args: []const []const u8) error{OutOfMemory} { | |||
pub fn punt_to_clang(arena: Allocator, args: []const []const u8) error{OutOfMemory} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these should be made public or used outside this file
Thanks for the review, folks!
These are already covered without this change 👍 Zig calls directly into As for what's left: I thought I had covered all of the usage of I'll dive in deeper tomorrow and see if I can eliminate the lingering references to |
This is a deficiency of zig compile errors; would be nice if it could explain how this dependency is being dragged in. Someday, we'll have it. For now, a workaround is to temporarily delete the spawn function from the std lib and then it tends to generate more helpful errors. |
665a9c5
to
b4056b7
Compare
3909724
to
3773f5e
Compare
This tip was a huge help; ended up being short work to track things down. I believe I've addressed all the feedback in the latest changes now. Let me know if anything still needs work 👍 |
Why is |
Nice catch. I updated the PR to use |
In accordance with the requesting issue (ziglang#10750): - `zig test` skips any tests that it cannot spawn, returning success - `zig run` and `zig build` exit with failure, reporting the command the cannot be run - `zig clang`, `zig ar`, etc. already punt directly to the appropriate clang/lld main(), even before this change - Native `libc` Detection is not supported Additionally, `exec()` and related Builder functions error at run-time, reporting the command that cannot be run
and adjust the warning message for invoking LLD twice in the same process.
d174dee
to
33fa296
Compare
Excellent work. Congrats on landing your first Zig PR 🎉 |
In accordance with the requesting issue (#10750):
zig test
skips any tests that it cannot spawn, returning successzig run
andzig build
exit with failure, reporting the command the cannot be runzig clang
,zig ar
, etc. already punt directly to the appropriate clang/lld main(), even before this changelibc
Detection is not supportedAdditionally,
exec()
and related Builder functions error at run-time, reporting the command that cannot be run