summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am5
-rw-r--r--changes/rust_cross2
-rw-r--r--configure.ac25
-rw-r--r--src/rust/.cargo/config.in5
-rw-r--r--src/rust/tor_rust/include.am4
5 files changed, 32 insertions, 9 deletions
diff --git a/Makefile.am b/Makefile.am
index 61451ed264..8fcf67924a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -31,8 +31,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
index 0000000000..d490403a28
--- /dev/null
+++ b/changes/rust_cross
@@ -0,0 +1,2 @@
+ o Minor feature (Rust, portability):
+ - Rust cross-compilation is now supported. Closes ticket 25895.
diff --git a/configure.ac b/configure.ac
index 116a51f7a3..a6d13820e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -443,6 +443,8 @@ fi
AC_C_BIGENDIAN
+AC_ARG_VAR([TARGET], [Rust target, must be specified when cross-compiling (CHOST != CBUILD). example: i386-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])
@@ -508,12 +510,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 "$TARGET"; then
+ if test "$host" = "$build"; then
+ AC_MSG_ERROR([CHOST = CBUILD is invalid if TARGET is specified, see configure --help for more information.])
+ fi
+ RUST_TARGET_PROP="target = '$TARGET'"
+ TOR_RUST_LIB_PATH="src/rust/target/$TARGET/release/$tor_rust_static_name"
+ else
+ if test "$host" != "$build"; then
+ AC_MSG_ERROR([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)
diff --git a/src/rust/.cargo/config.in b/src/rust/.cargo/config.in
index 70481bbcbe..6eddc75459 100644
--- a/src/rust/.cargo/config.in
+++ b/src/rust/.cargo/config.in
@@ -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@
diff --git a/src/rust/tor_rust/include.am b/src/rust/tor_rust/include.am
index c02324cb77..bcf94193f4 100644
--- a/src/rust/tor_rust/include.am
+++ b/src/rust/tor_rust/include.am
@@ -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