commit 70c067102b7d2576fa456d2872bb41abf559dff6 Author: Sebastian Hahn sebastian@torproject.org Date: Tue May 2 04:21:42 2017 +0200
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. --- .gitignore | 5 +++++ .gitmodules | 3 +++ Makefile.am | 1 + configure.ac | 29 +++++++++++++++++++++++++++++ src/ext/rust | 1 + src/rust/.cargo/config.in | 8 ++++++++ src/rust/Cargo.toml | 7 ------- src/rust/include.am | 3 ++- src/rust/tor_util/include.am | 1 + src/test/include.am | 1 + src/test/test_rust.sh | 2 +- 11 files changed, 52 insertions(+), 9 deletions(-)
diff --git a/.gitignore b/.gitignore index 68bad5f..0e0640d 100644 --- a/.gitignore +++ b/.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 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7074403 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "src/ext/rust"] + path = src/ext/rust + url = https://git.torproject.org/user/sebastian/tor-rust-dependencies diff --git a/Makefile.am b/Makefile.am index be4140a..79d2e78 100644 --- a/Makefile.am +++ b/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 diff --git a/configure.ac b/configure.ac index c5d3d44..9f67fe5 100644 --- a/configure.ac +++ b/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 ]) diff --git a/src/ext/rust b/src/ext/rust new file mode 160000 index 0000000..2402968 --- /dev/null +++ b/src/ext/rust @@ -0,0 +1 @@ +Subproject commit 240296800824e40b10cb8c16da0e711563353945 diff --git a/src/rust/.cargo/config.in b/src/rust/.cargo/config.in new file mode 100644 index 0000000..414b253 --- /dev/null +++ b/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@' diff --git a/src/rust/Cargo.toml b/src/rust/Cargo.toml index 527c536..fc4377e 100644 --- a/src/rust/Cargo.toml +++ b/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' - diff --git a/src/rust/include.am b/src/rust/include.am index e198049..20afc6c 100644 --- a/src/rust/include.am +++ b/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 diff --git a/src/rust/tor_util/include.am b/src/rust/tor_util/include.am index 863046b..17a755f 100644 --- a/src/rust/tor_util/include.am +++ b/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: diff --git a/src/test/include.am b/src/test/include.am index c0aca8a..829c282 100644 --- a/src/test/include.am +++ b/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)"; \ diff --git a/src/test/test_rust.sh b/src/test/test_rust.sh index 7c71008..4427c70 100755 --- a/src/test/test_rust.sh +++ b/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
tor-commits@lists.torproject.org