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

rustPlatform.buildRustPackage: packages that support cross compilation fail to build on platforms that are cross compilation targets #145726

Open
uri-canva opened this issue Nov 13, 2021 · 2 comments

Comments

@uri-canva
Copy link
Contributor

Describe the bug

If a package supports cross compilation upstream:
https://github.com/bvaisvil/zenith/blob/8f890291284870ea12e065ada0844100ad7aa7dc/.cargo/config
https://github.com/EFForg/apkeep/blob/0.6.0/.cargo/config.toml

then if we build the package with rustPlatform.buildRustPackage on a platform that matches a target then cargo will attempt to use that configuration for building, leading to errors like:

error: linker `aarch64-linux-gnu-gcc` not found
  |
  = note: No such file or directory (os error 2)

   Compiling instant v0.1.10
error: could not compile `encoding_rs` due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed
builder for '/nix/store/pqx5zpfzj6a90li969dqpw9q51zh6q6c-apkeep-0.6.0.drv' failed with exit code 101
error: build of '/nix/store/pqx5zpfzj6a90li969dqpw9q51zh6q6c-apkeep-0.6.0.drv' failed

https://github.com/NixOS/nixpkgs/pull/145452/checks?check_run_id=4174333214

This is because we always pass --target to it, regardless of whether it's cross compiling or not:

--target @rustTargetPlatformSpec@ \

cargo assumes it is cross compiling when --target is passed: rust-lang/cargo#5754 (comment)

The easiest fix is to delete the cross compilation configuration like in #107237.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Build apkeep on aarch64-linux.

Expected behavior

Successful build.

Additional context

#107237
#88616
#145452

Notify maintainers

@retrry

Metadata

  • system: "aarch64-darwin"
  • host os: Darwin 21.1.0, macOS 12.0.1
  • multi-user?: yes
  • sandbox: no
  • version: nix-env (Nix) 2.3.16
  • channels(root): "nixpkgs-21.11pre309670.253aecf69ed"
  • channels(uribaghin): "darwin, nixpkgs"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixpkgs
@uri-canva
Copy link
Contributor Author

Can we generalise this fix? Always delete .cargo/config.toml? Or delete the section that matches the host platform? Or change the way we invoke cargo to avoid --target when we're not cross compiling.

@jyooru
Copy link
Member

jyooru commented Nov 17, 2021

I've tested that deleting the linker configuration for a target fixes that target, and it does.

Instead of deleting .cargo/config.toml, would it be better to delete the linker configuration of each target? This way other configuration is still there.

I've tested that this script works to fix apkeep, and it does. It simply loads the configuration, removes linker configuration for each target and then saves it.

#!/usr/bin/env nix-shell
#! nix-shell -i python3 -p python3 python3Packages.toml
from os import path
import toml


if path.exists(".cargo/config.toml"):
    config = toml.load(open(".cargo/config.toml"))

    for target in config.get("target",{}).values():
        if "linker" in target:
            del target["linker"]

    toml.dump(config,open(".cargo/config.toml", "w"))
# .config/cargo.toml
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"

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

No branches or pull requests

2 participants