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

aarch64 build error: linker aarch64-linux-gnu-gcc not found #190

Closed
ahpohl opened this issue Dec 17, 2023 · 12 comments
Closed

aarch64 build error: linker aarch64-linux-gnu-gcc not found #190

ahpohl opened this issue Dec 17, 2023 · 12 comments

Comments

@ahpohl
Copy link

ahpohl commented Dec 17, 2023

I try to compile pgvecto.rs natively on Arch Linux Arm aarch64 and cargo selects the wrong linker. Instead of aarch64-unknown-gnu-gcc it tries to find aarch64-linux-gnu-gcc, which does not exist.

I followed the installation instructions as close as possible. Installed clang:

clang version 16.0.6
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-unknown-linux-gnu/12.1.0
Selected GCC installation: /usr/bin/../lib/gcc/aarch64-unknown-linux-gnu/12.1.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

the default toolchain using rustup and cargo-pgrx:

rustup toolchain install stable
cargo install cargo-pgrx --git https://github.com/tensorchord/pgrx.git --rev $(cat Cargo.toml | grep "pgrx =" | awk -F'rev = "' '{print $2}' | cut -d'"' -f1)

initialized cargo-pgrx to use the host postgresql instance:

cargo pgrx init --pg15 "/usr/bin/pg_config" 

Then I tried to compile pgvecto.rs (first deleted the rust_toolchain.toml file to not pull in all the other toolchains):

cargo pgrx install --sudo --release

output:

       Using PgConfig("pg15") and `pg_config` from /usr/bin/pg_config
    Building extension with features pg15
     Running command "/home/alarm/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/bin/cargo" "build" "--release" "--features" "pg15" "--no-default-features" "--message-format=json-render-diagnostics"
   Compiling proc-macro2 v1.0.70
   Compiling libc v0.2.151
   Compiling serde v1.0.193
   Compiling syn v1.0.109
error: linker `aarch64-linux-gnu-gcc` not found
  |
  = note: No such file or directory (os error 2)

error: could not compile `serde` (build script) due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `syn` (build script) due to previous error
error: could not compile `proc-macro2` (build script) due to previous error
error: could not compile `libc` (build script) due to previous error

Any ideas where cargo picks up the toolchain to use and how to fix it?
To me it looks as if I am attempting to cross-compile for aarch64, although this is a native compile on the target host.

@VoVAllen
Copy link
Member

We build the aarch release through cross compile, the details can be found at https://github.com/tensorchord/pgvecto.rs/blob/main/.github/workflows/release.yml#L82-L116. Also we have binary arm release at if needed.

@VoVAllen
Copy link
Member

Can you try with sudo apt-get -y install crossbuild-essential-arm64?

@ahpohl
Copy link
Author

ahpohl commented Dec 17, 2023

Can you try with sudo apt-get -y install crossbuild-essential-arm64?

I am on Arch Linux and trying to use the toolchains provided by rustup.

Also tried to cross-compile on host x86_64 for aarch64 target.

$ rustup target list
aarch64-apple-darwin (installed)
aarch64-apple-ios
aarch64-apple-ios-sim
aarch64-linux-android
aarch64-pc-windows-msvc
aarch64-unknown-fuchsia
aarch64-unknown-linux-gnu (installed)
aarch64-unknown-linux-musl
aarch64-unknown-none
aarch64-unknown-none-softfloat
aarch64-unknown-uefi
arm-linux-androideabi
arm-unknown-linux-gnueabi
arm-unknown-linux-gnueabihf
arm-unknown-linux-musleabi
arm-unknown-linux-musleabihf
armebv7r-none-eabi
armebv7r-none-eabihf
armv5te-unknown-linux-gnueabi
armv5te-unknown-linux-musleabi
armv7-linux-androideabi
armv7-unknown-linux-gnueabi
armv7-unknown-linux-gnueabihf
armv7-unknown-linux-musleabi
armv7-unknown-linux-musleabihf
armv7a-none-eabi
armv7r-none-eabi
armv7r-none-eabihf
asmjs-unknown-emscripten
i586-pc-windows-msvc
i586-unknown-linux-gnu
i586-unknown-linux-musl
i686-linux-android
i686-pc-windows-gnu
i686-pc-windows-msvc
i686-unknown-freebsd
i686-unknown-linux-gnu
i686-unknown-linux-musl
i686-unknown-uefi
loongarch64-unknown-linux-gnu
loongarch64-unknown-none
loongarch64-unknown-none-softfloat
nvptx64-nvidia-cuda
powerpc-unknown-linux-gnu
powerpc64-unknown-linux-gnu
powerpc64le-unknown-linux-gnu
riscv32i-unknown-none-elf
riscv32imac-unknown-none-elf
riscv32imc-unknown-none-elf
riscv64gc-unknown-linux-gnu
riscv64gc-unknown-none-elf
riscv64imac-unknown-none-elf
s390x-unknown-linux-gnu
sparc64-unknown-linux-gnu
sparcv9-sun-solaris
thumbv6m-none-eabi
thumbv7em-none-eabi
thumbv7em-none-eabihf
thumbv7m-none-eabi
thumbv7neon-linux-androideabi
thumbv7neon-unknown-linux-gnueabihf
thumbv8m.base-none-eabi
thumbv8m.main-none-eabi
thumbv8m.main-none-eabihf
wasm32-unknown-emscripten
wasm32-unknown-unknown
wasm32-wasi
wasm32-wasi-preview1-threads
x86_64-apple-darwin (installed)
x86_64-apple-ios
x86_64-fortanix-unknown-sgx
x86_64-linux-android
x86_64-pc-solaris
x86_64-pc-windows-gnu
x86_64-pc-windows-msvc
x86_64-sun-solaris
x86_64-unknown-freebsd
x86_64-unknown-fuchsia
x86_64-unknown-illumos
x86_64-unknown-linux-gnu (installed)
x86_64-unknown-linux-gnux32
x86_64-unknown-linux-musl
x86_64-unknown-netbsd
x86_64-unknown-none
x86_64-unknown-redox
x86_64-unknown-uefi

Interestingly, rustup doesn't provide a aarch64-linux-gnu target. Hence cross-compilation fails with the same error:

$ cargo build --target aarch64-unknown-linux-gnu --release
   Compiling serde v1.0.193
   Compiling eyre v0.6.9
   Compiling anyhow v1.0.75
   Compiling pest v2.7.5
   Compiling ring v0.17.7
error: failed to run custom build command for `ring v0.17.7`

Caused by:
  process didn't exit successfully: `/home/alex/git/pgvecto.rs/target/release/build/ring-7bf71631f3d5f310/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=RING_PREGENERATE_ASM
  cargo:rustc-env=RING_CORE_PREFIX=ring_core_0_17_7_
  OPT_LEVEL = Some("3")
  TARGET = Some("aarch64-unknown-linux-gnu")
  HOST = Some("x86_64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_aarch64-unknown-linux-gnu
  CC_aarch64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CC_aarch64_unknown_linux_gnu
  CC_aarch64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=TARGET_CC
  TARGET_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  RUSTC_LINKER = Some("aarch64-linux-gnu-gcc")
  cargo:rerun-if-env-changed=CROSS_COMPILE
  CROSS_COMPILE = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("neon")
  cargo:rerun-if-env-changed=CFLAGS_aarch64-unknown-linux-gnu
  CFLAGS_aarch64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64_unknown_linux_gnu
  CFLAGS_aarch64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  running: "aarch64-linux-gnu-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-I" "include" "-I" "/home/alex/git/pgvecto.rs/target/aarch64-unknown-linux-gnu/release/build/ring-4425aa70a16eabe6/out" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-pedantic" "-Wall" "-Wextra" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-g3" "-DNDEBUG" "-o" "/home/alex/git/pgvecto.rs/target/aarch64-unknown-linux-gnu/release/build/ring-4425aa70a16eabe6/out/crypto/curve25519/curve25519.o" "-c" "crypto/curve25519/curve25519.c"

  --- stderr


  error occurred: Failed to find tool. Is `aarch64-linux-gnu-gcc` installed?


warning: build failed, waiting for other jobs to finish...

I guess the deb package crossbuild-essential-arm64 contains the toolchain triple named aarch64-linux-gnu instead of aarch64-unknown-linux-gnu. Which build file specifies to use the aarch64-linux-gnu target?

@VoVAllen
Copy link
Member

Do you have aarch64-linux-gnu-gcc on arch? Not sure why it said it's not found

@ahpohl
Copy link
Author

ahpohl commented Dec 17, 2023

Do you have aarch64-linux-gnu-gcc on arch? Not sure why it said it's not found

Yes, that would be there on x86_64. But using this cross-toolchain instead of the toolchain(s) provided by rustup would mean I have to always cross-compile. Is the toolchain hard-coded somewhere? In my understanding cargo natively should do just the right thing, and if you want to cross-compile, download and use the one you specify with the --target option.

EDIT: Installed this toolchain and it now at least finds the cross-compile toolchain. But it seems to ignore the --target option all together. Not a very satisfying situation. Where can I change it?

I really don't understand the purpose of the rust-toolchain.toml file:

[toolchain]
channel = "nightly-2023-11-15"
components = ["rustfmt", "clippy", "miri"]
targets = [
    "x86_64-unknown-linux-gnu",
    "x86_64-apple-darwin",
    "aarch64-unknown-linux-gnu",
    "aarch64-apple-darwin",
]

Here the right supported rustup toolchains are specified but it seems they are overridden with aarch64-linux-gnu somewhere as the --target option and also the ~/.cargo/config file are simply ignored.

@usamoi
Copy link
Collaborator

usamoi commented Dec 17, 2023

aarch64-linux-gnu-gcc is the name of aarch64 gcc on both Arch Linux and Ubuntu. You can delete

linker = "aarch64-linux-gnu-gcc"
to make it work on Arch Linux Arm. Or you can just create a link named aarch64-linux-gnu-gcc in path.

@usamoi
Copy link
Collaborator

usamoi commented Dec 17, 2023

Cargo does always find the system linker for cross compilation if you do not specify one so we add this line to make cross compilation work. Probably we need find the right linker and set the environment variable in build.rs since not all distros follow the same name convention.

@ahpohl
Copy link
Author

ahpohl commented Dec 17, 2023

Cargo does always find the system linker for cross compilation if you do not specify one so we add this line to make cross compilation work. Probably we need find the right linker and set the environment variable in build.rs since not all distros follow the same name convention.

Why is it not possible to pull the right rustup toolchain in your docker image for cross-compilation instead of installing the extra Ubuntu deb package?

@usamoi
Copy link
Collaborator

usamoi commented Dec 17, 2023

It's possible. However, building in Docker with qemu-aarch64 is too slow.

@ahpohl
Copy link
Author

ahpohl commented Dec 17, 2023

aarch64-linux-gnu-gcc is the name of aarch64 gcc on both Arch Linux and Ubuntu.

On Arch Linux Arm the gcc compiler is called aarch64-unknown-gnu-gcc, hence I have the issue when I tried to compile natively.

$ ls -la /usr/bin/aarch64*
-rwxr-xr-x 4 root root 1371672 May 28  2022 /usr/bin/aarch64-unknown-linux-gnu-c++
-rwxr-xr-x 4 root root 1371672 May 28  2022 /usr/bin/aarch64-unknown-linux-gnu-g++
-rwxr-xr-x 3 root root 1363512 May 28  2022 /usr/bin/aarch64-unknown-linux-gnu-gcc
-rwxr-xr-x 3 root root 1363512 May 28  2022 /usr/bin/aarch64-unknown-linux-gnu-gcc-12.1.0
-rwxr-xr-x 2 root root   30792 May 28  2022 /usr/bin/aarch64-unknown-linux-gnu-gcc-ar
-rwxr-xr-x 2 root root   30816 May 28  2022 /usr/bin/aarch64-unknown-linux-gnu-gcc-nm
-rwxr-xr-x 2 root root   30824 May 28  2022 /usr/bin/aarch64-unknown-linux-gnu-gcc-ranlib
``

@usamoi
Copy link
Collaborator

usamoi commented Dec 17, 2023

installing the extra Ubuntu deb package

It's necessary for cross compilation from x86_64 to aarch64. Not only for Rust, if you cross compiles with clang, you still need to install these deb packages.

@ahpohl
Copy link
Author

ahpohl commented Dec 17, 2023

aarch64-linux-gnu-gcc is the name of aarch64 gcc on both Arch Linux and Ubuntu. You can delete

linker = "aarch64-linux-gnu-gcc"

to make it work on Arch Linux Arm. Or you can just create a link named aarch64-linux-gnu-gcc in path.

Thanks @usamoi for pointing this out. After deleting .cargo/config the native compiler is being picked up now.

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

No branches or pull requests

3 participants