Skip to content

Commit

Permalink
Allow Rust build using locally supplied crates or crates.io
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shahn authored and nmathewson committed May 19, 2017
1 parent aeba64e commit 70c0671
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/ext/rust"]
path = src/ext/rust
url = https://git.torproject.org/user/sebastian/tor-rust-dependencies
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,4 @@ mostlyclean-local:

clean-local:
rm -rf $(top_builddir)/src/rust/target
rm -rf $(top_builddir)/src/rust/.cargo/registry
29 changes: 29 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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])
Expand Down Expand Up @@ -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
])
Expand Down
1 change: 1 addition & 0 deletions src/ext/rust
Submodule rust added at 240296
8 changes: 8 additions & 0 deletions src/rust/.cargo/config.in
Original file line number Diff line number Diff line change
@@ -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@'
7 changes: 0 additions & 7 deletions src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

3 changes: 2 additions & 1 deletion src/rust/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions src/rust/tor_util/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions src/test/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)"; \
Expand Down
2 changes: 1 addition & 1 deletion src/test/test_rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 70c0671

Please sign in to comment.