[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Don't try to link C from rust doctests for nss detection



commit a8ac21fbb5f22b68ffa019b575085c142293bc40
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Sun Sep 16 14:34:31 2018 -0400

    Don't try to link C from rust doctests for nss detection
    
    This is really annoying, since we can't use cfg(test) for doctests.
---
 src/rust/Cargo.toml              |  6 ++++++
 src/rust/crypto/Cargo.toml       |  6 ++++++
 src/rust/external/Cargo.toml     |  6 ++++++
 src/rust/protover/Cargo.toml     |  6 +++++-
 src/rust/protover/protover.rs    | 14 ++++++++++++--
 src/rust/smartlist/Cargo.toml    |  6 ++++++
 src/rust/tor_allocate/Cargo.toml |  6 ++++++
 src/rust/tor_log/Cargo.toml      |  5 +++++
 src/rust/tor_rust/Cargo.toml     |  6 ++++++
 src/rust/tor_util/Cargo.toml     |  6 ++++++
 src/test/test_rust.sh            |  1 +
 11 files changed, 65 insertions(+), 3 deletions(-)

diff --git a/src/rust/Cargo.toml b/src/rust/Cargo.toml
index 4bbadbe53..e399dbb33 100644
--- a/src/rust/Cargo.toml
+++ b/src/rust/Cargo.toml
@@ -23,3 +23,9 @@ default = []
 test-c-from-rust = [
     "crypto/test-c-from-rust",
 ]
+
+# We have to define a feature here because doctests don't get cfg(test),
+# and we need to disable some C dependencies when running the doctests
+# because of the various linker issues.  See
+# https://github.com/rust-lang/rust/issues/45599
+test_linking_hack = []
diff --git a/src/rust/crypto/Cargo.toml b/src/rust/crypto/Cargo.toml
index d68ac48e2..6ebfe0dc1 100644
--- a/src/rust/crypto/Cargo.toml
+++ b/src/rust/crypto/Cargo.toml
@@ -30,3 +30,9 @@ rand_core = { version = "=0.2.0-pre.0", default-features = false }
 # execute with `cargo test`.  Due to numerous linker issues (#25386), this is
 # currently disabled by default.
 test-c-from-rust = []
+
+# We have to define a feature here because doctests don't get cfg(test),
+# and we need to disable some C dependencies when running the doctests
+# because of the various linker issues.  See
+# https://github.com/rust-lang/rust/issues/45599
+test_linking_hack = []
diff --git a/src/rust/external/Cargo.toml b/src/rust/external/Cargo.toml
index 60ec03be4..4735144ee 100644
--- a/src/rust/external/Cargo.toml
+++ b/src/rust/external/Cargo.toml
@@ -14,3 +14,9 @@ name = "external"
 path = "lib.rs"
 crate_type = ["rlib", "staticlib"]
 
+[features]
+# We have to define a feature here because doctests don't get cfg(test),
+# and we need to disable some C dependencies when running the doctests
+# because of the various linker issues.  See
+# https://github.com/rust-lang/rust/issues/45599
+test_linking_hack = []
diff --git a/src/rust/protover/Cargo.toml b/src/rust/protover/Cargo.toml
index a8480e142..2f7783e76 100644
--- a/src/rust/protover/Cargo.toml
+++ b/src/rust/protover/Cargo.toml
@@ -4,6 +4,11 @@ version = "0.0.1"
 name = "protover"
 
 [features]
+# We have to define a feature here because doctests don't get cfg(test),
+# and we need to disable some C dependencies when running the doctests
+# because of the various linker issues.  See
+# https://github.com/rust-lang/rust/issues/45599
+test_linking_hack = []
 
 [dependencies]
 libc = "=0.2.39"
@@ -27,4 +32,3 @@ path = "../tor_log"
 name = "protover"
 path = "lib.rs"
 crate_type = ["rlib", "staticlib"]
-
diff --git a/src/rust/protover/protover.rs b/src/rust/protover/protover.rs
index 7b3f808cb..8417d8595 100644
--- a/src/rust/protover/protover.rs
+++ b/src/rust/protover/protover.rs
@@ -10,7 +10,6 @@ use std::str::FromStr;
 use std::string::String;
 
 use external::c_tor_version_as_new_as;
-use external::c_tor_is_using_nss;
 
 use errors::ProtoverError;
 use protoset::ProtoSet;
@@ -125,6 +124,17 @@ impl From<Protocol> for UnknownProtocol {
     }
 }
 
+#[cfg(feature="test_linking_hack")]
+fn have_linkauth_v1() -> bool {
+    true
+}
+
+#[cfg(not(feature="test_linking_hack"))]
+fn have_linkauth_v1() -> bool {
+    use external::c_tor_is_using_nss;
+    ! c_tor_is_using_nss()
+}
+
 /// Get a CStr representation of current supported protocols, for
 /// passing to C, or for converting to a `&str` for Rust.
 ///
@@ -142,7 +152,7 @@ impl From<Protocol> for UnknownProtocol {
 ///
 //  C_RUST_COUPLED: protover.c `protover_get_supported_protocols`
 pub(crate) fn get_supported_protocols_cstr() -> &'static CStr {
-    if c_tor_is_using_nss() {
+    if ! have_linkauth_v1() {
         cstr!("Cons=1-2 \
                Desc=1-2 \
                DirCache=1-2 \
diff --git a/src/rust/smartlist/Cargo.toml b/src/rust/smartlist/Cargo.toml
index 6ddcbee8e..4ecdf5086 100644
--- a/src/rust/smartlist/Cargo.toml
+++ b/src/rust/smartlist/Cargo.toml
@@ -11,3 +11,9 @@ name = "smartlist"
 path = "lib.rs"
 crate_type = ["rlib", "staticlib"]
 
+[features]
+# We have to define a feature here because doctests don't get cfg(test),
+# and we need to disable some C dependencies when running the doctests
+# because of the various linker issues.  See
+# https://github.com/rust-lang/rust/issues/45599
+test_linking_hack = []
diff --git a/src/rust/tor_allocate/Cargo.toml b/src/rust/tor_allocate/Cargo.toml
index 468425f11..7bb3b9887 100644
--- a/src/rust/tor_allocate/Cargo.toml
+++ b/src/rust/tor_allocate/Cargo.toml
@@ -11,3 +11,9 @@ name = "tor_allocate"
 path = "lib.rs"
 crate_type = ["rlib", "staticlib"]
 
+[features]
+# We have to define a feature here because doctests don't get cfg(test),
+# and we need to disable some C dependencies when running the doctests
+# because of the various linker issues.  See
+# https://github.com/rust-lang/rust/issues/45599
+test_linking_hack = []
diff --git a/src/rust/tor_log/Cargo.toml b/src/rust/tor_log/Cargo.toml
index 9d06299c0..1aa9be061 100644
--- a/src/rust/tor_log/Cargo.toml
+++ b/src/rust/tor_log/Cargo.toml
@@ -9,6 +9,11 @@ path = "lib.rs"
 crate_type = ["rlib", "staticlib"]
 
 [features]
+# We have to define a feature here because doctests don't get cfg(test),
+# and we need to disable some C dependencies when running the doctests
+# because of the various linker issues.  See
+# https://github.com/rust-lang/rust/issues/45599
+test_linking_hack = []
 
 [dependencies]
 libc = "0.2.39"
diff --git a/src/rust/tor_rust/Cargo.toml b/src/rust/tor_rust/Cargo.toml
index 86fad3ee7..1523ee0dd 100644
--- a/src/rust/tor_rust/Cargo.toml
+++ b/src/rust/tor_rust/Cargo.toml
@@ -14,3 +14,9 @@ path = "../tor_util"
 [dependencies.protover]
 path = "../protover"
 
+[features]
+# We have to define a feature here because doctests don't get cfg(test),
+# and we need to disable some C dependencies when running the doctests
+# because of the various linker issues.  See
+# https://github.com/rust-lang/rust/issues/45599
+test_linking_hack = []
diff --git a/src/rust/tor_util/Cargo.toml b/src/rust/tor_util/Cargo.toml
index a606a280b..51e4bd9c5 100644
--- a/src/rust/tor_util/Cargo.toml
+++ b/src/rust/tor_util/Cargo.toml
@@ -17,3 +17,9 @@ path = "../tor_log"
 [dependencies]
 libc = "=0.2.39"
 
+[features]
+# We have to define a feature here because doctests don't get cfg(test),
+# and we need to disable some C dependencies when running the doctests
+# because of the various linker issues.  See
+# https://github.com/rust-lang/rust/issues/45599
+test_linking_hack = []
diff --git a/src/test/test_rust.sh b/src/test/test_rust.sh
index 4afc84285..a1a56af48 100755
--- a/src/test/test_rust.sh
+++ b/src/test/test_rust.sh
@@ -10,6 +10,7 @@ for cargo_toml_dir in "${abs_top_srcdir:-../../..}"/src/rust/*; do
 	cd "${abs_top_builddir:-../../..}/src/rust" && \
 	    CARGO_TARGET_DIR="${abs_top_builddir:-../../..}/src/rust/target" \
 	    "${CARGO:-cargo}" test ${CARGO_ONLINE-"--frozen"} \
+	    --features "test_linking_hack" \
 	    ${EXTRA_CARGO_OPTIONS} \
 	    --manifest-path "${cargo_toml_dir}/Cargo.toml" || exitcode=1
     fi

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits