Skip to content

Cross compilation support. #82

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Toasterson opened this issue Jan 7, 2024 · 4 comments
Closed

Cross compilation support. #82

Toasterson opened this issue Jan 7, 2024 · 4 comments

Comments

@Toasterson
Copy link

Hey all.

I am trying to compile the rust compiler to aarch64_unknown_illumos from my x86_64_unknown_illumos system. However as described in rust-lang/rust#112936 I get the following error.

error: failed to run custom build command for `psm v0.1.21`

Caused by:
  process didn't exit successfully: `/var/lib/abuild/rust/build/x86_64-unknown-illumos/stage1-rustc/release/build/psm-61c9c6ef89c427d5/build-script-build` (exit status: 1)
  --- stdout
  OPT_LEVEL = Some("3")
  TARGET = Some("aarch64-unknown-illumos")
  HOST = Some("x86_64-unknown-illumos")
  cargo:rerun-if-env-changed=CC_aarch64-unknown-illumos
  CC_aarch64-unknown-illumos = None
  cargo:rerun-if-env-changed=CC_aarch64_unknown_illumos
  CC_aarch64_unknown_illumos = Some("gcc")
  cargo:rerun-if-env-changed=CFLAGS_aarch64-unknown-illumos
  CFLAGS_aarch64-unknown-illumos = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64_unknown_illumos
  CFLAGS_aarch64_unknown_illumos = Some("-ffunction-sections -fdata-sections -fPIC")
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = Some("neon")
  cargo:rustc-cfg=asm
  cargo:rustc-cfg=switchable_stack
  running: "gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-ffunction-sections" "-fdata-sections" "-fPIC" "-xassembler-with-cpp" "-DCFG_TARGET_OS_illumos" "-DCFG_TARGET_ARCH_aarch64" "-DCFG_TARGET_ENV_" "-o" "/var/lib/abuild/rust/build/x86_64-unknown-illumos/stage1-rustc/aarch64-unknown-illumos/release/build/psm-a54651dd69990eb0/out/src/arch/aarch_aapcs64.o" "-c" "src/arch/aarch_aapcs64.s"
  cargo:warning=src/arch/aarch_aapcs64.s: Assembler messages:
  cargo:warning=src/arch/aarch_aapcs64.s:35: Error: no such instruction: `orr w0,wzr,'
  cargo:warning=src/arch/aarch_aapcs64.s:48: Error: operand size mismatch for `mov'
  cargo:warning=src/arch/aarch_aapcs64.s:62: Error: operand size mismatch for `mov'
  cargo:warning=src/arch/aarch_aapcs64.s:63: Error: no such instruction: `br x1'
  cargo:warning=src/arch/aarch_aapcs64.s:75: Error: no such instruction: `stp x29,x30,[sp,'
  cargo:warning=src/arch/aarch_aapcs64.s:76: Error: bad register expression
  cargo:warning=src/arch/aarch_aapcs64.s:77: Error: operand size mismatch for `mov'
  cargo:warning=src/arch/aarch_aapcs64.s:78: Error: bad register expression
  cargo:warning=src/arch/aarch_aapcs64.s:79: Error: bad register expression
  cargo:warning=src/arch/aarch_aapcs64.s:80: Error: bad register expression
  cargo:warning=src/arch/aarch_aapcs64.s:81: Error: operand size mismatch for `mov'
  cargo:warning=src/arch/aarch_aapcs64.s:82: Error: no such instruction: `blr x2'
  cargo:warning=src/arch/aarch_aapcs64.s:83: Error: operand size mismatch for `mov'
  cargo:warning=src/arch/aarch_aapcs64.s:84: Error: bad register expression
  cargo:warning=src/arch/aarch_aapcs64.s:85: Error: no such instruction: `ldp x29,x30,[sp],'
  cargo:warning=src/arch/aarch_aapcs64.s:86: Error: bad register expression
  cargo:warning=src/arch/aarch_aapcs64.s:87: Error: bad register expression
  cargo:warning=src/arch/aarch_aapcs64.s:88: Error: bad register expression
  exit status: 1

  --- stderr


  error occurred: Command "gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-ffunction-sections" "-fdata-sections" "-fPIC" "-xassembler-with-cpp" "-DCFG_TARGET_OS_illumos" "-DCFG_TARGET_ARCH_aarch64" "-DCFG_TARGET_ENV_" "-o" "/var/lib/abuild/rust/build/x86_64-unknown-illumos/stage1-rustc/aarch64-unknown-illumos/release/build/psm-a54651dd69990eb0/out/src/arch/aarch_aapcs64.o" "-c" "src/arch/aarch_aapcs64.s" with args "gcc" did not execute successfully (status code exit status: 1).

From waht I can read out gcc build does not understand that ARM assembler. Do you know how to setup a usable cross compiler on linux or another unix OS? if I have the guide to setup the compiler properly or the packages and the OS this build script assumes I can copy the packaging to our system. Alternatively could we get Variables we can set during build to sepecify a different compiler binary so I can force the rust build to use the ARM cross compiler instead of the native system one?

@nagisa
Copy link
Member

nagisa commented Jan 8, 2024

When cross-compiling with gcc you need to make sure that you specify the cross-compiler (since there isn’t a “default”). Neither rust nor the ecosystem guess what it might be, and usually default to plain gcc binary, which in your case is going to be an x86_64 targetting gcc compiler.

The relevant environment variables can already be seen in the error output.

@Toasterson
Copy link
Author

Thanks for confirming my suspicion so I can use CC_aarch64_unknown_illumos and need to make sure it gets set troughout the build env. Is there a specific reason this Variable is not compatible with rutc's default compiler setting?

@nagisa
Copy link
Member

nagisa commented Jan 8, 2024

This crate like many others in the ecosystem uses cc-rs crate for compiling native code. It just so happens that psm is probably the first in the dependency chain and the first to report an error. Since rustc cross-compiles just fine for many other targets, it must be a misconfiguration (or lack of changes in x.py) or something along those lines pertaining to your target specifically.

@nagisa
Copy link
Member

nagisa commented Feb 19, 2024

Triage: closing as this was a question, not a bug and does not need to be tracked.

@nagisa nagisa closed this as completed Feb 19, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants