cross icon indicating copy to clipboard operation
cross copied to clipboard

Unusupported os in target when running inside devenv.sh

Open byrnedo opened this issue 8 months ago • 10 comments

Checklist

Describe your issue

When I run within devenv, rustc --print sysroot points to /nix/store/h9dd5l5zqf7yzyjbyb2895mwgaxbq0vp-rust-mixed

This seems to throw off cross, and I get the following error when trying to compile anything

cross -v build  --target aarch64-unknown-linux-gnu --release --locked
+ cargo metadata --format-version 1 --filter-platform aarch64-unknown-linux-gnu
[cross] warning: Found conflicting cross configuration in `/Users/doby/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/getrandom-0.3.2/Cargo.toml`, use `[workspace.metadata.cross]` in the workspace manifest instead.
Currently only using configuration from `/Users/doby/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/getrandom-0.2.15/Cargo.toml`
+ rustc --print sysroot
Error: 
   0: could not determine os in target triplet
   1: unsupported os in target, abi: "mixed", system: "rust" 

Location:
   src/docker/image.rs:342

What target(s) are you cross-compiling for?

No response

Which operating system is the host (e.g computer cross is on) running?

  • [x] macOS
  • [ ] Windows
  • [ ] Linux / BSD
  • [ ] other OS (specify in description)

What architecture is the host?

  • [ ] x86_64 / AMD64
  • [ ] arm32
  • [x] arm64 (including Mac M1)

What container engine is cross using?

  • [x] docker
  • [ ] podman
  • [ ] other container engine (specify in description)

cross version

0.2.5 (4090bec 2024-10-15)

Example

No response

Additional information / notes

No response

byrnedo avatar May 06 '25 09:05 byrnedo

I'm also running into this, have you found any workaround?

meenzen avatar Jun 24 '25 20:06 meenzen

We do not support non-rustup installations, you can try with CROSS_CUSTOM_TOOLCHAIN=x86_64-unknown-linux-gnu (set this to the name of the toolchain to be used in the container cross spins up, usually x86_64-unknown-linux-gnu, but can be changed if the image supports it) It will most likely fail due to missing components, cross/rustc needs the target installed in rustlib

Emilgardis avatar Jun 24 '25 21:06 Emilgardis

I'm also running into this, have you found any workaround?

I've tried doing direnv deny within the project, then cd ~ followed by cd -, and then running cross hoping it will work with the host's version of rustup, but something is still tripping it up.

byrnedo avatar Jun 25 '25 04:06 byrnedo

We do not support non-rustup installations, you can try with CROSS_CUSTOM_TOOLCHAIN=x86_64-unknown-linux-gnu (set this to the name of the toolchain to be used in the container cross spins up, usually x86_64-unknown-linux-gnu, but can be changed if the image supports it) It will most likely fail due to missing components, cross/rustc needs the target installed in rustlib

Ok, thanks for the info. Yeah it got further this time but failed on a step trying to use the rustup command.

byrnedo avatar Jun 25 '25 04:06 byrnedo

@byrnedo It sounds like you might be hitting the issue that #1697 fixes.

To get cross working, I copied and adapted the packaging code from nixpkgs:

# cross.nix
{ pkgs, lib, ... }:

pkgs.rustPackages.rustPlatform.buildRustPackage rec {
  pname = "cargo-cross";
  version = "e281947";

  src = pkgs.fetchFromGitHub {
    owner = "cross-rs";
    repo = "cross";
    rev = "e281947ca900da425e4ecea7483cfde646c8a1ea";
    sha256 = "sha256-92fpq9lsnxU51X8Mmk/34fd4921nu8tFJYLVgIm35kk=";
  };

  useFetchCargoVendor = true;
  cargoHash = "sha256-wUWhWbnjKTPiAlc/c8TR7GM4nLhcO4ARZH+7sAc8BHo=";

  checkFlags = [
    "--skip=docker::shared::tests::directories::test_host"

    # The following tests require empty CARGO_BUILD_TARGET env variable, but we
    # set it ever since https://github.com/NixOS/nixpkgs/pull/298108.
    "--skip=config::tests::test_config::no_env_and_no_toml_default_target_then_none"
    "--skip=config::tests::test_config::no_env_but_toml_default_target_then_use_toml"
  ];
}

Then in devenv.nix:

let
  crossPkg = pkgs.callPackage ./cross.nix { };
in
{
  # ... other code ...

  env.CROSS_CUSTOM_TOOLCHAIN = "1";
  # Adapt this for your use case:
  env.CROSS_CUSTOM_TOOLCHAIN_COMPAT = "x86_64-amd64-linux-musl";

  enterShell = ''
    export PATH="${crossPkg}/bin:$PATH"
  '';

  # ... other code ...
}

Once the PR above is included in a stable release, it should be possible for us Nix people to get cross working again with only the CROSS_CUSTOM_TOOLCHAIN* environment variables.

liammcdermott avatar Aug 05 '25 20:08 liammcdermott

@byrnedo It sounds like you might be hitting the issue that #1697 fixes.

To get cross working, I copied and adapted the packaging code from nixpkgs:

# cross.nix
{ pkgs, lib, ... }:

pkgs.rustPackages.rustPlatform.buildRustPackage rec {
  pname = "cargo-cross";
  version = "e281947";

  src = pkgs.fetchFromGitHub {
    owner = "cross-rs";
    repo = "cross";
    rev = "e281947ca900da425e4ecea7483cfde646c8a1ea";
    sha256 = "sha256-92fpq9lsnxU51X8Mmk/34fd4921nu8tFJYLVgIm35kk=";
  };

  useFetchCargoVendor = true;
  cargoHash = "sha256-wUWhWbnjKTPiAlc/c8TR7GM4nLhcO4ARZH+7sAc8BHo=";

  checkFlags = [
    "--skip=docker::shared::tests::directories::test_host"

    # The following tests require empty CARGO_BUILD_TARGET env variable, but we
    # set it ever since https://github.com/NixOS/nixpkgs/pull/298108.
    "--skip=config::tests::test_config::no_env_and_no_toml_default_target_then_none"
    "--skip=config::tests::test_config::no_env_but_toml_default_target_then_use_toml"
  ];
}

Then in devenv.nix:

let
  crossPkg = pkgs.callPackage ./cross.nix { };
in
{
  # ... other code ...

  env.CROSS_CUSTOM_TOOLCHAIN = "1";
  # Adapt this for your use case:
  env.CROSS_CUSTOM_TOOLCHAIN_COMPAT = "x86_64-amd64-linux-musl";

  enterShell = ''
    export PATH="${crossPkg}/bin:$PATH"
  '';

  # ... other code ...
}

Once the PR above is included in a stable release, it should be possible for us Nix people to get cross working again with only the CROSS_CUSTOM_TOOLCHAIN* environment variables.

Oh great, I'll try this out tomorrow

byrnedo avatar Aug 05 '25 20:08 byrnedo

@liammcdermott I finally got round to trying this but I still get the same issue where cross is trying to sniff the toolchain name from the path:

...-pre-build sh -c 'PATH="$PATH":"/nix/store/svws5njndpkrp6j9725j08c2xpnw7grq-rust-stable-1.89.0-1.89.0/bin" cargo -v build --target aarch64-unknown-linux-gnu --release --locked'
exec /bin/sh: exec format error
+ rustup component list --toolchain svws5njndpkrp6j9725j08c2xpnw7grq-rust-stable-1.89.0-1.89.0
Error: 
   0: `rustup component list --toolchain svws5njndpkrp6j9725j08c2xpnw7grq-rust-stable-1.89.0-1.89.0` failed with exit status: 1

Stderr:
   error: error: invalid value 'svws5njndpkrp6j9725j08c2xpnw7grq-rust-stable-1.89.0-1.89.0' for '--toolchain <toolchain>': invalid toolchain name: 'svws5njndpkrp6j9725j08c2xpnw7grq-rust-stable-1.89.0-1.89.0'

byrnedo avatar Sep 06 '25 20:09 byrnedo

Ya, seems I hit same as @byrnedo ; though the issue could be renamed. It's not related to devenv.sh per-se; just running from a flake shell.

Sewer56 avatar Sep 27 '25 20:09 Sewer56

In any case, if you use both CROSS_CUSTOM_TOOLCHAIN and install the target to be ran inside cross e.g.

++ [
  targets.powerpc-unknown-linux-gnu.latest.rust-std
]

for fenix or

# Cross-compilation targets for testing
targets = [
  "x86_64-unknown-linux-gnu"
  "powerpc64-unknown-linux-gnu" # For big-endian testing
];

for devenv.sh , you should be fine.

https://github.com/cachix/devenv/issues/866

Sewer56 avatar Sep 27 '25 20:09 Sewer56

In any case, if you use both CROSS_CUSTOM_TOOLCHAIN and install the target to be ran inside cross e.g.

++ [
  targets.powerpc-unknown-linux-gnu.latest.rust-std
]

for fenix or

# Cross-compilation targets for testing
targets = [
  "x86_64-unknown-linux-gnu"
  "powerpc64-unknown-linux-gnu" # For big-endian testing
];

for devenv.sh , you should be fine.

https://github.com/cachix/devenv/issues/866

I must have missed that issue, I'll give this a go

byrnedo avatar Sep 28 '25 12:09 byrnedo