alexcrichton / openssl-src-rs

Source code and logic to build OpenSSL from source
Apache License 2.0
69 stars 114 forks source link

Error while cross compiling from Windows 10 to Raspberry Pi 2 (armv7-unknown-linux-gnueabihf) #118

Closed adumbidiot closed 11 months ago

adumbidiot commented 2 years ago

Hello, I just ran into an issue trying to use the vendored feature to cross-compile from Windows 10 to a Raspberry Pi 2. I am using the nightly-x86_64-pc-windows-msvc toolchain. The exact error can be seen in the captured stderr when the build fails:

C:/SysGCC/raspberry/bin/arm-linux-gnueabihf-ar: creating apps/libapps.a
  crypto/cversion.c: In function 'OpenSSL_version':
  crypto/cversion.c:38:44: error: incomplete universal character name \U
           return "ENGINESDIR: \"" ENGINESDIR "\"";
                                              ^~~~
  crypto/cversion.c:38:44: warning: unknown escape sequence: '\D'
  crypto/cversion.c:38:44: warning: unknown escape sequence: '\h'
  crypto/cversion.c:38:44: warning: unknown escape sequence: '\d'
  crypto/cversion.c:38:44: warning: unknown escape sequence: '\o'
  crypto/cversion.c:38:44: warning: unknown escape sequence: '\o'
  crypto/cversion.c:38:44: warning: unknown escape sequence: '\o'
  crypto/cversion.c:38:44: warning: unknown escape sequence: '\i'
  make[1]: *** [Makefile:2254: crypto/cversion.o] Error 1
  make: *** [Makefile:177: build_libs] Error 2

For my build, I specified the following environment variables:

PERL = "C:/Users/nathaniel/scoop/apps/msys2/current/usr/bin/perl" 

CC = "C:/SysGCC/raspberry/bin/arm-linux-gnueabihf-gcc"
CXX = "C:/SysGCC/raspberry/bin/arm-linux-gnueabihf-g++"

CMAKE_GENERATOR = "Ninja"

I also set the linker through RUSTFLAGS as C:/SysGCC/raspberry/bin/arm-linux-gnueabihf-gcc. I set my target as armv7-unknown-linux-gnueabihf.

I tracked this down to ENGINESDIR having backslashes instead of forward slashes, and I tracked it back to the prefix option in the configure script. Currently, this library uses the following to set the prefix:

if host.contains("pc-windows-gnu") {
    configure.arg(&format!("--prefix={}", sanitize_sh(&install_dir)));
} else {
    configure.arg(&format!("--prefix={}", install_dir.display()));
}

I edited the bottom case to instead be configure.arg(&format!("--prefix={}", install_dir.to_str().unwrap().replace('\\', "/")));. I don't particularly understand the ramifications of this change, but it seems to fix my build. sanitize_sh seems to only be applicable for Mingw as it tries to change the paths from Windows style to Mingw style. Could this be fixed by adding another case for windows msvc?

ShootingKing-AM commented 2 years ago

I edited the bottom case to instead be configure.arg(&format!("--prefix={}", install_dir.to_str().unwrap().replace('\', "/")));. I don't particularly understand the ramifications of this change, but it seems to fix my build. sanitize_sh seems to only be applicable for Mingw as it tries to change the paths from Windows style to Mingw style.

I am also facing the same issue, How did you do that ? How did you change your Cargo.toml to include your local copy and build that ?

adumbidiot commented 2 years ago

See https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html

ShootingKing-AM commented 2 years ago

i did this in Cargo.toml

env: using git-bash shell on windows targeting to cross-compile for android-linux:

openssl-src::Build
target = aarch64-linux-android
host = x86_64-pc-windows-msvc
out_dir = D:\Users\Documents\GitHub\aw-android\aw-server-rust\target\aarch64-linux-android\debug\build\openssl-sys-7f3055406159564a\out\openssl-build
build_dir = D:\Users\Documents\GitHub\aw-android\aw-server-rust\target\aarch64-linux-android\debug\build\openssl-sys-7f3055406159564a\out\openssl-build\build
install_dir = D:\Users\Documents\GitHub\aw-android\aw-server-rust\target\aarch64-linux-android\debug\build\openssl-sys-7f3055406159564a\out\openssl-build\install
is cfg Windows = false
...
# openssl-sys = { path = "../openssl-sys", features = ["vendored"], version = "0.9.58" }
openssl-sys = { version = "0.9.58", features = ["vendored"]}

[patch.crates-io]
openssl-src = { path = "../openssl-src" }
openssl-sys = { path = "../openssl-sys" }

and still

 crypto/cversion.c:38:33: error: \U used with no following hex digits
          return "ENGINESDIR: \"" ENGINESDIR "\"";
                                  ^~~~~~~~~~
  <command line>:13:23: note: expanded from here
  #define ENGINESDIR "D:\Users\Documents\GitHub\aw-android\aw-server-rust\target\aarch64-linux-android\debug\build\openssl-sys-ee67b57d3d3215a1\out\openssl-build\install/lib/engines-1.1"
                        ^~
  crypto/cversion.c:38:33: warning: unknown escape sequence '\D' [-Wunknown-escape-sequence]
          return "ENGINESDIR: \"" ENGINESDIR "\"";
                                  ^~~~~~~~~~
  <command line>:13:29: note: expanded from here
  #define ENGINESDIR "D:\Users\Documents\GitHub\aw-android\aw-server-rust\target\aarch64-linux-android\debug\build\openssl-sys-ee67b57d3d3215a1\out\openssl-build\install/lib/engines-1.1"
                              ^~
  crypto/cversion.c:38:33: warning: unknown escape sequence '\G' [-Wunknown-escape-sequence]
          return "ENGINESDIR: \"" ENGINESDIR "\"";
                                  ^~~~~~~~~~
  <command line>:13:39: note: expanded from here
  #define ENGINESDIR "D:\Users\Documents\GitHub\aw-android\aw-server-rust\target\aarch64-linux-android\debug\build\openssl-sys-ee67b57d3d3215a1\out\openssl-build\install/lib/engines-1.1"
                                        ^~
  crypto/cversion.c:38:33: warning: unknown escape sequence '\d' [-Wunknown-escape-sequence]
          return "ENGINESDIR: \"" ENGINESDIR "\"";
                                  ^~~~~~~~~~
  <command line>:13:101: note: expanded from here
  #define ENGINESDIR "D:\Users\Documents\GitHub\aw-android\aw-server-rust\target\aarch64-linux-android\debug\build\openssl-sys-ee67b57d3d3215a1\out\openssl-build\install/lib/engines-1.1"
                                                                                                      ^~
  crypto/cversion.c:38:33: error: expected '{' after '\d' escape sequence
          return "ENGINESDIR: \"" ENGINESDIR "\"";
                                  ^~~~~~~~~~
  <command line>:13:113: note: expanded from here
  #define ENGINESDIR "D:\Users\Documents\GitHub\aw-android\aw-server-rust\target\aarch64-linux-android\debug\build\openssl-sys-ee67b57d3d3215a1\out\openssl-build\install/lib/engines-1.1"
                                                                                                                  ^~
  crypto/cversion.c:38:33: error: expected '{' after '\d' escape sequence
          return "ENGINESDIR: \"" ENGINESDIR "\"";
                                  ^~~~~~~~~~
  <command line>:13:142: note: expanded from here
  #define ENGINESDIR "D:\Users\Documents\GitHub\aw-android\aw-server-rust\target\aarch64-linux-android\debug\build\openssl-sys-ee67b57d3d3215a1\out\openssl-build\install/lib/engines-1.1"
                                                                                                                                               ^~
  crypto/cversion.c:38:33: error: expected '{' after '\d' escape sequence
          return "ENGINESDIR: \"" ENGINESDIR "\"";
                                  ^~~~~~~~~~
  <command line>:13:146: note: expanded from here
  #define ENGINESDIR "D:\Users\Documents\GitHub\aw-android\aw-server-rust\target\aarch64-linux-android\debug\build\openssl-sys-ee67b57d3d3215a1\out\openssl-build\install/lib/engines-1.1"
                                                                                                                                                   ^~
  crypto/cversion.c:38:33: warning: unknown escape sequence '\i' [-Wunknown-escape-sequence]
          return "ENGINESDIR: \"" ENGINESDIR "\"";
                                  ^~~~~~~~~~
  <command line>:13:160: note: expanded from here
  #define ENGINESDIR "D:\Users\Documents\GitHub\aw-android\aw-server-rust\target\aarch64-linux-android\debug\build\openssl-sys-ee67b57d3d3215a1\out\openssl-build\install/lib/engines-1.1"
                                                                                                                                                                 ^~
  4 warnings and 4 errors generated.
  make[3]: *** [crypto/cversion.o] Error 1
  make[2]: *** [build_libs] Error 2
  thread 'main' panicked at '

  Error building OpenSSL:
      Command: "make" "build_libs"
      Exit status: exit code: 2

      ', C:\Users\user\.cargo\registry\src\github.com-1ecc6299db9ec823\openssl-src-111.22.0+1.1.1q\src\lib.rs:490:13
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
make[1]: *** [android] Error 101
make[1]: Leaving directory `D:/Users/Documents/GitHub/aw-android/aw-server-rust'
make: *** [aw-server-rust/target/armv7-linux-androideabi/debug/libaw_server.so] Error 2

C:\Users\user\.cargo\registry\src\github.com-1ecc6299db9ec823\openssl-src-111.22.0+1.1.1q\src\lib.rs:490:13 - its still going somewhere else and not the ../openssl-src or ../openssl-sys

Not that good with rust building ( feels like shet :/ ) Can you spoonfeed a little please @adumbidiot 🥺 Edit: Thanks ! I was able to edit openssl-src now, and i fixed my build ty :3