]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix Rust cross compilation.
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>
Wed, 16 May 2018 23:35:12 +0000 (19:35 -0400)
committerTaylor Yu <catalyst@torproject.org>
Wed, 27 Jun 2018 19:42:06 +0000 (14:42 -0500)
Makefile.am
changes/rust_cross [new file with mode: 0644]
configure.ac
src/rust/.cargo/config.in
src/rust/tor_rust/include.am

index 58ff9fb3e8505391808020bfb38fc23ad26b5824..552b75a35fd095cbbe258b42f34d079acb14bfa3 100644 (file)
@@ -26,8 +26,9 @@ TESTING_TOR_BINARY=$(top_builddir)/src/or/tor$(EXEEXT)
 endif
 
 if USE_RUST
-rust_ldadd=$(top_builddir)/src/rust/target/release/@TOR_RUST_STATIC_NAME@ \
-       @TOR_RUST_EXTRA_LIBS@
+## this MUST be $(), otherwise am__DEPENDENCIES will not track it
+rust_ldadd=$(top_builddir)/$(TOR_RUST_LIB_PATH) \
+       $(TOR_RUST_EXTRA_LIBS)
 else
 rust_ldadd=
 endif
diff --git a/changes/rust_cross b/changes/rust_cross
new file mode 100644 (file)
index 0000000..d490403
--- /dev/null
@@ -0,0 +1,2 @@
+  o Minor feature (Rust, portability):
+    - Rust cross-compilation is now supported. Closes ticket 25895.
index f557faf1c66038642e1f0313fe5e205ff993d956..27cb0323c25051ee7e8cd831d01aaf7eae99b2d1 100644 (file)
@@ -453,6 +453,8 @@ fi
 
 AC_C_BIGENDIAN
 
+AC_ARG_VAR([TOR_RUST_TARGET], [Rust target, must be specified when cross-compiling (HOST != BUILD). example: i686-pc-windows-gnu])
+
 if test "x$enable_rust" = "xyes"; then
   AC_ARG_VAR([RUSTC], [path to the rustc binary])
   AC_CHECK_PROG([RUSTC], [rustc], [rustc],[no])
@@ -518,12 +520,29 @@ if test "x$enable_rust" = "xyes"; then
   dnl For now both MSVC and MinGW rust libraries will output static libs with
   dnl the MSVC naming convention.
   if test "$bwin32" = "true"; then
-    TOR_RUST_STATIC_NAME=tor_rust.lib
+    tor_rust_static_name=tor_rust.lib
   else
-    TOR_RUST_STATIC_NAME=libtor_rust.a
+    tor_rust_static_name=libtor_rust.a
+  fi
+
+  AC_CANONICAL_BUILD
+
+  if test -n "$TOR_RUST_TARGET"; then
+    if test "$host" = "$build"; then
+      AC_MSG_ERROR([HOST = BUILD is invalid if TOR_RUST_TARGET is specified, see configure --help for more information.])
+    fi
+    RUST_TARGET_PROP="target = '$TOR_RUST_TARGET'"
+    TOR_RUST_LIB_PATH="src/rust/target/$TOR_RUST_TARGET/release/$tor_rust_static_name"
+  else
+    if test "$host" != "$build"; then
+      AC_MSG_ERROR([TOR_RUST_TARGET must be specified when cross-compiling with Rust enabled.])
+    fi
+    RUST_TARGET_PROP=
+    TOR_RUST_LIB_PATH="src/rust/target/release/$tor_rust_static_name"
   fi
 
-  AC_SUBST(TOR_RUST_STATIC_NAME)
+  AC_SUBST(RUST_TARGET_PROP)
+  AC_SUBST(TOR_RUST_LIB_PATH)
   AC_SUBST(CARGO_ONLINE)
   AC_SUBST(RUST_WARN)
   AC_SUBST(RUST_DL)
index 70481bbcbe9780d77fb8e10804b322fd64bf9c42..6eddc75459c2e4201fbaea9cedf695082c58bf56 100644 (file)
@@ -7,5 +7,6 @@
 @RUST_DL@ [source.vendored-sources]
 @RUST_DL@ directory = '@TOR_RUST_DEPENDENCIES@'
 
-@RUST_WARN@ [build]
-@RUST_WARN@ rustflags = [ "-D", "warnings" ]
\ No newline at end of file
+[build]
+@RUST_WARN@ rustflags = [ "-D", "warnings" ]
+@RUST_TARGET_PROP@
index c02324cb7730755d51f625a229148904d50385d2..bcf94193f430c2130cc7815ffa2981248063b09f 100644 (file)
@@ -4,7 +4,7 @@ EXTRA_DIST +=\
 
 EXTRA_CARGO_OPTIONS=
 
-src/rust/target/release/@TOR_RUST_STATIC_NAME@: FORCE
+@TOR_RUST_LIB_PATH@: FORCE
        ( cd "$(abs_top_builddir)/src/rust" ; \
                CARGO_TARGET_DIR="$(abs_top_builddir)/src/rust/target" \
                CARGO_HOME="$(abs_top_builddir)/src/rust" \
@@ -22,7 +22,7 @@ distclean-rust:
        rm -rf "$(abs_top_builddir)/src/rust/registry"
 
 if USE_RUST
-build-rust: src/rust/target/release/@TOR_RUST_STATIC_NAME@
+build-rust: @TOR_RUST_LIB_PATH@
 else
 build-rust:
 endif