briansmith / ring

Safe, fast, small crypto using Rust
Other
3.74k stars 704 forks source link

Unable to cross compile to Windows from Linux #894

Open Daijobou opened 5 years ago

Daijobou commented 5 years ago

I use windows 10 and compiling my rust app as target windows is successful. Now I tried to compile it for linux but its failed. I installed cygwin on windows 10 to get a linux compiler.

# rustup show
Default host: x86_64-pc-windows-msvc

installed toolchains
--------------------
stable-x86_64-pc-windows-msvc
nightly-2019-08-01-x86_64-pc-windows-msvc
nightly-x86_64-pc-windows-msvc (default)

installed targets for active toolchain
--------------------------------------
x86_64-pc-windows-msvc
x86_64-unknown-linux-gnu
x86_64-unknown-linux-musl

active toolchain
----------------
nightly-x86_64-pc-windows-msvc (default)
rustc 1.39.0-nightly (9eae1fc0e 2019-08-23)

.cargo/config:

[build]
target = "x86_64-unknown-linux-gnu"

[target.x86_64-unknown-linux-gnu]
linker = "C:/cygwin64/bin/x86_64-pc-cygwin-gcc.exe"
ar = "C:/cygwin64/bin/x86_64-pc-cygwin-gcc-ar.exe"

created a bat-file for compiling:

SET TARGET_CC=C:/cygwin64/bin/x86_64-pc-cygwin-gcc.exe
SET TARGET_AR=C:/cygwin64/bin/x86_64-pc-cygwin-gcc-ar.exe
cargo build --release --target x86_64-unknown-linux-gnu

Its compiling about 190 modules successul but stops always for "ring v0.13.5". Last lines of failed build:

   Compiling url v1.7.2
   Compiling mime v0.2.6
   Compiling aho-corasick v0.7.4
   Compiling csv-core v0.1.6
error: failed to run custom build command for `ring v0.13.5`

Caused by:
  process didn't exit successfully: `MyProject\target\release\build\ring-a0370e8063fcbf6b\build-script-build` (exit code: 101)
--- stdout
CARGO: \\?\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\bin\cargo.exe
CARGO_CFG_DEBUG_ASSERTIONS:
CARGO_CFG_PROC_MACRO:
CARGO_CFG_TARGET_ARCH: x86_64
CARGO_CFG_TARGET_ENDIAN: little
CARGO_CFG_TARGET_ENV: gnu
CARGO_CFG_TARGET_FAMILY: unix
CARGO_CFG_TARGET_FEATURE: fxsr,mmx,sse,sse2
CARGO_CFG_TARGET_HAS_ATOMIC: 16,32,64,8,cas,ptr
CARGO_CFG_TARGET_OS: linux
CARGO_CFG_TARGET_POINTER_WIDTH: 64
CARGO_CFG_TARGET_THREAD_LOCAL:
CARGO_CFG_TARGET_VENDOR: unknown
CARGO_CFG_UNIX:
CARGO_FEATURE_DEFAULT: 1
CARGO_FEATURE_DEV_URANDOM_FALLBACK: 1
CARGO_FEATURE_USE_HEAP: 1
CARGO_HOME: .cargo
CARGO_MAKEFLAGS: --jobserver-fds=__rust_jobserver_semaphore_2422853318 --jobserver-auth=__rust_jobserver_semaphore_2422853318
CARGO_MANIFEST_DIR: .cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5
CARGO_MANIFEST_LINKS: ring-asm
CARGO_PKG_AUTHORS: Brian Smith <brian@briansmith.org>
CARGO_PKG_DESCRIPTION: Safe, fast, small crypto using Rust.
CARGO_PKG_HOMEPAGE:
CARGO_PKG_NAME: ring
CARGO_PKG_REPOSITORY: https://github.com/briansmith/ring
CARGO_PKG_VERSION: 0.13.5
CARGO_PKG_VERSION_MAJOR: 0
CARGO_PKG_VERSION_MINOR: 13
CARGO_PKG_VERSION_PATCH: 5
CARGO_PKG_VERSION_PRE:
DEBUG: false
FP_NO_HOST_CHECK: NO
HOST: x86_64-pc-windows-msvc
LD_LIBRARY_PATH: .rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib
OS: Windows_NT
OUT_DIR: MyProject\target\x86_64-unknown-linux-gnu\release\build\ring-ec4818b779f4b1b4\out
RUSTC: rustc
RUSTC_LINKER: C:/cygwin64/bin/x86_64-pc-cygwin-gcc.exe
RUSTDOC: rustdoc
RUSTUP_HOME: .rustup
RUSTUP_TOOLCHAIN: nightly-x86_64-pc-windows-msvc
RUST_RECURSION_COUNT: 1
TARGET: x86_64-unknown-linux-gnu
TARGET_AR: C:/cygwin64/bin/x86_64-pc-cygwin-gcc-ar.exe
TARGET_CC: C:/cygwin64/bin/x86_64-pc-cygwin-gcc.exe
OPT_LEVEL = Some("3")
TARGET = Some("x86_64-unknown-linux-gnu")
HOST = Some("x86_64-pc-windows-msvc")
CC_x86_64-unknown-linux-gnu = None
CC_x86_64_unknown_linux_gnu = None
TARGET_CC = Some("C:/cygwin64/bin/x86_64-pc-cygwin-gcc.exe")
CFLAGS_x86_64-unknown-linux-gnu = None
CFLAGS_x86_64_unknown_linux_gnu = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,mmx,sse,sse2")
running "C:/cygwin64/bin/x86_64-pc-cygwin-gcc.exe" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-declarations" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-Wno-cast-align" "-fstack-protector" "-g3" "-DNDEBUG" "-D_XOPEN_SOURCE=700" "-c" "-oC:\\Users\\Username\\MyProject\\target\\x86_64-unknown-linux-gnu\\release\\build\\ring-ec4818b779f4b1b4\\out\\aes-x86_64-elf.o" "C:\\Users\\Username\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\ring-0.13.5\\pregenerated\\aes-x86_64-elf.S"

--- stderr
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S: Assembler messages:
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:9: Warning: .type pseudo-op used outside of .def/.endef: ignored.
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:9: Error: junk at end of line, first unrecognized character is `_'
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:161: Warning: .size pseudo-op used outside of .def/.endef: ignored.
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:161: Error: junk at end of line, first unrecognized character is `_'
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:162: Warning: .type pseudo-op used outside of .def/.endef: ignored.
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:162: Error: junk at end of line, first unrecognized character is `_'
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:334: Warning: .size pseudo-op used outside of .def/.endef: ignored.
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:334: Error: junk at end of line, first unrecognized character is `_'
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:337: Error: unknown pseudo-op: `.hidden'
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:338: Warning: .type pseudo-op used outside of .def/.endef: ignored.
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:338: Error: junk at end of line, first unrecognized character is `G'
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:339: Error: unknown pseudo-op: `.hidden'
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:418: Warning: .size pseudo-op used outside of .def/.endef: ignored.
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:418: Error: junk at end of line, first unrecognized character is `G'
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:421: Error: unknown pseudo-op: `.hidden'
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:422: Warning: .type pseudo-op used outside of .def/.endef: ignored.
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:422: Error: junk at end of line, first unrecognized character is `G'
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:458: Warning: .size pseudo-op used outside of .def/.endef: ignored.
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:458: Error: junk at end of line, first unrecognized character is `G'
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:460: Warning: .type pseudo-op used outside of .def/.endef: ignored.
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:460: Error: junk at end of line, first unrecognized character is `_'
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:635: Warning: .size pseudo-op used outside of .def/.endef: ignored.
.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\pregenerated\aes-x86_64-elf.S:635: Error: junk at end of line, first unrecognized character is `_'
thread 'main' panicked at 'execution failed', .cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.13.5\build.rs:645:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

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

Is here a solution? Make I a mistake in settings?

Dependencies: "rocket_http" "cookie" "ring"

UPDATE: I have forced rocket to use master which use cookie v12 instead v11 with now ring v14. But this still fails with the same errors.

andrewtj commented 5 years ago

I'm not sure cygwin supplies a cross compiler. I've successfully cross-compiled from Windows to Linux using the cross musl toolchain from https://win.musl.cc/.

briansmith commented 4 years ago

Did you try using clang instead of GCC? Then it might work.

sztomi commented 2 years ago

For anyone coming to this issue, I managed to cross-compile ring with a custom clang toolchain this way:

In .cargo/config.toml:

[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-clang++"
env = { TARGET_CC="x86_64-w64-mingw32-clang", TARGET_AR="llvm-ar" }
rustflags = [ "-L", "/usr/lib/gcc/x86_64-w64-mingw32/10-win32" ]

and then building as

$ cargo build --target x86_64-pc-windows-gnu

I'm not sure if the linker path above is strictly needed for ring itself, since I was building my own application that depends on ring, so it might not be necessary for others.