Unverified Commit da8e1980 authored by Matthew Finkel's avatar Matthew Finkel
Browse files

Bug 40208: Mitigate uniffi non-deterministic code generation

parent bde528ac
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
diff --git a/uniffi_bindgen/src/interface/types.rs b/uniffi_bindgen/src/interface/types.rs
index 6448d58..b7efd22 100644
--- a/uniffi_bindgen/src/interface/types.rs
+++ b/uniffi_bindgen/src/interface/types.rs
@@ -26,7 +26,7 @@
 use anyhow::bail;
 use anyhow::Result;
 use std::convert::TryFrom;
-use std::{collections::hash_map::Entry, collections::HashMap, collections::HashSet};
+use std::{collections::hash_map::Entry, collections::HashMap, collections::BTreeSet};
 
 use super::Attributes;
 
@@ -71,7 +71,7 @@ pub enum FFIType {
 /// Represents all the different high-level types that can be used in a component interface.
 /// At this level we identify user-defined types by name, without knowing any details
 /// of their internal structure apart from what type of thing they are (record, enum, etc).
-#[derive(Debug, Clone, Eq, PartialEq, Hash)]
+#[derive(Debug, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)]
 pub enum Type {
     // Primitive types.
     UInt8,
@@ -195,7 +195,7 @@ pub(crate) struct TypeUniverse {
     // Named type definitions (including aliases).
     type_definitions: HashMap<String, Type>,
     // All the types in the universe, by canonical type name.
-    all_known_types: HashSet<Type>,
+    all_known_types: BTreeSet<Type>,
 }
 
 impl TypeUniverse {
+8 −0
Original line number Diff line number Diff line
@@ -22,6 +22,14 @@ replace-with = "vendored-sources"
directory = "/var/tmp/build/uniffi-rs/vendor"
EOF

# We change the data type of the `all_known_types` Set from HashSet to BTreeSet.
# Uniffi iterates over the elements of this set, and iteration over a HashSet occurs
# in an arbitrary order, while iteration over a BTreeSet orders in a defined (and
# deterministic) order. This patch solves a build reproducibility issue, see
# tor-browser-build#40208.
#
# Upstream bug: https://github.com/mozilla/uniffi-rs/issues/374
patch -p1 < $rootdir/btreeset.patch
# We usually use --frozen but there is no Cargo.lock file available. Thus resort
# to --offline.
cargo build --release --offline --target x86_64-unknown-linux-gnu
+1 −0
Original line number Diff line number Diff line
@@ -15,3 +15,4 @@ input_files:
  # `cargo vendor vendor` in the `uniffi-rs` directory has vendored the sources.
  - URL: https://people.torproject.org/~gk/mirrors/sources/uniffi-rs-vendor-[% c('version') %].tar.bz2
    sha256sum: 71d912237208c35a762b3c812afe0a758823792dd745c1253314bcccc1694b7f
  - filename: btreeset.patch