Skip to content

std::env::args_os always returns an empty iterator in a musl+gcompat environment #124126

Closed
@rjsberry

Description

@rjsberry

I tried this code in Alpine Linux cross compiled to x86_64-unknown-linux-gnu:

use std::env;

fn main() {
    println!("{:?}", env::args_os().collect::<Vec<_>>());
}

For reference I ran this in a container on an M1 Macbook:

$ docker run --rm -it --platform linux/amd64 alpine
# apk add gcompat libgcc

I always see [] printed, even when I pass the program arguments.

I'm not sure this is an issue with the environment as the following C program works as expected:

#include <stdio.h>

int main(int argc, char **argv) {
    for (int i = 0; i < argc; i++) {
        printf("%d: %s\n", i, argv[i]);
    }
}

Meta

rustc +nightly --version --verbose:

rustc 1.79.0-nightly (becebb315 2024-04-17)
binary: rustc
commit-hash: becebb3158149a115cad8a402612e25436a7e37b
commit-date: 2024-04-17
host: aarch64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-muslTarget: The musl libcT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions