Skip to content
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

Centralize environ setup. #23402

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jsirois
Copy link

@jsirois jsirois commented Mar 29, 2025

Move processing of std.os.environ centrally to std.os and provide a
hook for discovering the raw environ block for libraries that don't
link libc.

Fixes #23372
Affects #4524

Move processing of std.os.environ centrally to std.os and provide a
hook for discovering the raw environ block for libraries that don't
link libc.

Fixes ziglang#23372
Affects ziglang#4524
@jsirois
Copy link
Author

jsirois commented Mar 29, 2025

With this, my #23372 use case sees the following compile error:

install
└─ install pexcz
   └─ zig build-lib pexcz Debug native 1 errors
/home/jsirois/dev/ziglang/zig/lib/std/os.zig:82:21: error: missing std.options.environ_setupFn: there is no way to collect environment variables.
                    @compileError(
                    ^~~~~~~~~~~~~

And fixes it in its root file with:

pub const std_options: std.Options = .{
    .environ_setupFn = if (builtin.link_libc) null else posixEnviron,
};

var environ: ?[*:null]?[*:0]u8 = null;

fn posixEnviron() [*:null]?[*:0]u8 {
    return environ.?;
}

// N.B.: This is the main entry point called by Python code via ctypes.
fn bootPosix(
    python: [*:0]const u8,
    pex: [*:0]const u8,
    original_argv: [*:null]?[*:0]const u8,
    envp: [*:null]?[*:0]u8,
) callconv(.c) c_int {
    environ = envp;
    // ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

std.process.Child is not useable for Linux libraries not linking libc even when an env_map is provided.
1 participant