tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

build.rs (1913B)


      1 fn main() {
      2    cc::Build::new()
      3        .files(vec![
      4            "src/context.c",
      5            "src/equix.c",
      6            "src/solver.c",
      7            "hashx/src/blake2.c",
      8            "hashx/src/compiler.c",
      9            "hashx/src/compiler_a64.c",
     10            "hashx/src/compiler_x86.c",
     11            "hashx/src/context.c",
     12            "hashx/src/hashx.c",
     13            "hashx/src/program.c",
     14            "hashx/src/program_exec.c",
     15            "hashx/src/siphash.c",
     16            "hashx/src/siphash_rng.c",
     17            "hashx/src/virtual_memory.c",
     18        ])
     19        // Activate our patch for hashx_rng_callback
     20        .define("HASHX_RNG_CALLBACK", "1")
     21        // Equi-X always uses HashX size 8 (64-bit output)
     22        .define("HASHX_SIZE", "8")
     23        // Avoid shared library API declarations, link statically
     24        .define("HASHX_STATIC", "1")
     25        .define("EQUIX_STATIC", "1")
     26        .includes(vec!["include", "src", "hashx/include", "hashx/src"])
     27        .compile("equix");
     28 
     29    // Run bindgen to automatically extract types and functions. This time set
     30    // HASHX_SHARED and EQUIX_SHARED, so the function symbols are not hidden.
     31    let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
     32    bindgen::Builder::default()
     33        .header_contents(
     34            "wrapper.h",
     35            r#"
     36                #define HASHX_RNG_CALLBACK 1
     37                #define HASHX_SIZE 8
     38                #define HASHX_SHARED 1
     39                #define EQUIX_SHARED 1
     40                #include "hashx/include/hashx.h"
     41                #include "include/equix.h"
     42            "#,
     43        )
     44        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
     45        .default_enum_style(bindgen::EnumVariation::Rust {
     46            non_exhaustive: true,
     47        })
     48        .bitfield_enum(".*_flags")
     49        .generate()
     50        .unwrap()
     51        .write_to_file(out_path.join("bindings.rs"))
     52        .unwrap();
     53 }