Browse Source

Allow Rust build using locally supplied crates or crates.io

This adds a couple of configure commands to control whether we're
requiring all dependencies to be available locally (default) or not
(--enable-cargo-online-mode). When building from a tarball, we require
the RUST_DEPENDENCIES variable to point to the local repository of
crates. This also adds src/ext/rust as a git submodule that contains
such a local repository for easy setup.
Sebastian Hahn 7 years ago
parent
commit
70c067102b
11 changed files with 52 additions and 9 deletions
  1. 5 0
      .gitignore
  2. 3 0
      .gitmodules
  3. 1 0
      Makefile.am
  4. 29 0
      configure.ac
  5. 1 0
      src/ext/rust
  6. 8 0
      src/rust/.cargo/config.in
  7. 0 7
      src/rust/Cargo.toml
  8. 2 1
      src/rust/include.am
  9. 1 0
      src/rust/tor_util/include.am
  10. 1 0
      src/test/include.am
  11. 1 1
      src/test/test_rust.sh

+ 5 - 0
.gitignore

@@ -173,6 +173,11 @@ uptime-*.json
 /src/or/libtor-testing.a
 /src/or/libtor.lib
 
+# /src/rust
+/src/rust/.cargo/config
+/src/rust/.cargo/registry
+/src/rust/target
+
 # /src/test
 /src/test/Makefile
 /src/test/Makefile.in

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "src/ext/rust"]
+	path = src/ext/rust
+	url = https://git.torproject.org/user/sebastian/tor-rust-dependencies

+ 1 - 0
Makefile.am

@@ -239,3 +239,4 @@ mostlyclean-local:
 
 clean-local:
 	rm -rf $(top_builddir)/src/rust/target
+	rm -rf $(top_builddir)/src/rust/.cargo/registry

+ 29 - 0
configure.ac

@@ -254,6 +254,9 @@ if test "x$PYTHON" = "x"; then
 fi
 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
 
+dnl List all external rust crates we depend on here. Include the version
+rust_crates="libc-0.2.22"
+AC_SUBST(rust_crates)
 
 if test "x$enable_rust" = "xyes"; then
   AC_ARG_VAR([RUSTC], [path to the rustc binary])
@@ -271,10 +274,35 @@ if test "x$enable_rust" = "xyes"; then
   AC_DEFINE([HAVE_RUST], 1, [have Rust])
   if test "x$enable_cargo_online_mode" = "xyes"; then
     CARGO_ONLINE=
+    RUST_DL=#
   else
     CARGO_ONLINE=--frozen
+    RUST_DL=
+
+    dnl When we're not allowed to touch the network, we need crate dependencies
+    dnl locally available.
+    AC_MSG_CHECKING([rust crate dependencies])
+    AC_ARG_VAR([RUST_DEPENDENCIES], [path to directory with local crate mirror])
+    if test "x$RUST_DEPENDENCIES" = "x"; then
+      RUST_DEPENDENCIES="$srcdir/src/ext/rust/"
+      NEED_MOD=1
+    fi
+    if test ! -d "$RUST_DEPENDENCIES"; then
+      AC_MSG_ERROR([Rust dependency directory $RUST_DEPENDENCIES does not exist. Specify a dependency directory using the RUST_DEPENDENCIES variable or allow cargo to fetch crates using --enable-cargo-online-mode.])
+    fi
+    for dep in $rust_crates; do
+      if test ! -d "$RUST_DEPENDENCIES"/"$dep"; then
+        AC_MSG_ERROR([Failure to find rust dependency $RUST_DEPENDENCIES/$dep. Specify a dependency directory using the RUST_DEPENDENCIES variable or allow cargo to fetch crates using --enable-cargo-online-mode.])
+      fi
+    done
+    if test "x$NEED_MOD" = "x1"; then
+      dnl When looking for dependencies from cargo, pick right directory
+      RUST_DEPENDENCIES="../../src/ext/rust"
+    fi
   fi
+
   AC_SUBST(CARGO_ONLINE)
+  AC_SUBST(RUST_DL)
 
 dnl Let's check the rustc version, too
   AC_MSG_CHECKING([rust version])
@@ -2065,6 +2093,7 @@ AC_CONFIG_FILES([
         contrib/dist/tor.service
         src/config/torrc.sample
         src/config/torrc.minimal
+        src/rust/.cargo/config
         scripts/maint/checkOptionDocs.pl
         scripts/maint/updateVersions.pl
 ])

+ 1 - 0
src/ext/rust

@@ -0,0 +1 @@
+Subproject commit 240296800824e40b10cb8c16da0e711563353945

+ 8 - 0
src/rust/.cargo/config.in

@@ -0,0 +1,8 @@
+[source]
+
+@RUST_DL@ [source.crates-io]
+@RUST_DL@ registry = 'https://github.com/rust-lang/crates.io-index'
+@RUST_DL@ replace-with = 'vendored-sources'
+
+@RUST_DL@ [source.vendored-sources]
+@RUST_DL@ directory = '@RUST_DEPENDENCIES@'

+ 0 - 7
src/rust/Cargo.toml

@@ -5,10 +5,3 @@ members = ["tor_util"]
 debug = true
 panic = "abort"
 
-[source.crates-io]
-registry = 'https://github.com/rust-lang/crates.io-index'
-replace-with = 'vendored-sources'
-
-[source.vendored-sources]
-directory = 'vendor'
-

+ 2 - 1
src/rust/include.am

@@ -2,4 +2,5 @@ include src/rust/tor_util/include.am
 
 EXTRA_DIST +=\
 	src/rust/Cargo.toml \
-	src/rust/Cargo.lock
+	src/rust/Cargo.lock \
+	src/rust/.cargo/config.in

+ 1 - 0
src/rust/tor_util/include.am

@@ -7,6 +7,7 @@ EXTRA_DIST +=\
 src/rust/target/release/libtor_util.a: FORCE
 	( cd "$(abs_top_srcdir)/src/rust/tor_util" ; \
 		CARGO_TARGET_DIR="$(abs_top_builddir)/src/rust/target" \
+		HOME="$(abs_top_builddir)/src/rust" \
 		$(CARGO) build --release --quiet $(CARGO_ONLINE) )
 
 FORCE:

+ 1 - 0
src/test/include.am

@@ -5,6 +5,7 @@ TESTS_ENVIRONMENT = \
 	export PYTHON="$(PYTHON)"; \
 	export SHELL="$(SHELL)"; \
 	export abs_top_srcdir="$(abs_top_srcdir)"; \
+	export abs_top_builddir="$(abs_top_builddir)"; \
 	export builddir="$(builddir)"; \
 	export TESTING_TOR_BINARY="$(TESTING_TOR_BINARY)"; \
 	export CARGO="$(CARGO)"; \

+ 1 - 1
src/test/test_rust.sh

@@ -7,7 +7,7 @@ exitcode=0
 
 for crate in $crates; do
     cd "${abs_top_srcdir:-.}/src/rust/${crate}"
-    "${CARGO:-cargo}" test ${CARGO_ONLINE-"--frozen"} || exitcode=1
+    CARGO_TARGET_DIR="${abs_top_builddir}/src/rust/target" HOME="${abs_top_builddir}/src/rust" "${CARGO:-cargo}" test ${CARGO_ONLINE-"--frozen"} || exitcode=1
 done
 
 exit $exitcode