diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd5ed921c..21fa75f6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,7 +74,7 @@ jobs: strategy: matrix: # "windows-latest" was removed; see https://github.com/ZcashFoundation/zcash_script/issues/38 - os: [ubuntu-latest, macOS-latest] + os: [ubuntu-latest, macOS-latest, windows-latest] steps: - uses: actions/checkout@v4 with: @@ -85,16 +85,10 @@ jobs: # - name: install LLVM on Mac # if: matrix.os == 'macOS-latest' # run: brew install llvm - - name: install LLVM on Windows - if: matrix.os == 'windows-latest' - run: | - choco install llvm -y - echo "C:\Program Files\LLVM\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - echo "LIBCLANG_PATH=C:\Program Files\LLVM\bin" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - uses: actions-rs/toolchain@v1 if: matrix.os == 'windows-latest' with: - target: x86_64-pc-windows-gnu + target: x86_64-pc-windows-msvc toolchain: stable profile: minimal override: true @@ -108,7 +102,7 @@ jobs: if: matrix.os == 'windows-latest' with: command: test - args: --target x86_64-pc-windows-gnu + args: --target x86_64-pc-windows-msvc - uses: actions-rs/cargo@v1 if: matrix.os != 'windows-latest' with: diff --git a/Cargo.lock b/Cargo.lock index e8e99d0bc..ec667537d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,13 +25,14 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.3" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +checksum = "8b79b82693f705137f8fb9b37871d99e4f9a7df12b917eed79c3d3954830a60b" dependencies = [ "cfg-if", "once_cell", "version_check", + "zerocopy", ] [[package]] @@ -96,17 +97,17 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.68.1" +version = "0.69.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "726e4313eb6ec35d2730258ad4e15b547ee75d6afaa1361a922e78e59b7d8078" +checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" dependencies = [ "bitflags 2.4.0", "cexpr", "clang-sys", + "itertools", "lazy_static", "lazycell", "log", - "peeking_take_while", "prettyplease", "proc-macro2", "quote", @@ -691,6 +692,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "jobserver" version = "0.1.26" @@ -995,12 +1005,6 @@ dependencies = [ "password-hash", ] -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -1877,6 +1881,26 @@ dependencies = [ "zcash_proofs", ] +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.35", +] + [[package]] name = "zeroize" version = "1.6.0" diff --git a/README.md b/README.md index 90814b535..91ad908ad 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,11 @@ work correctly. Since we don't allow those in our repository, we start over every time, basically using it as a glorified `git clone`. This issue is being tracked in https://github.com/ZcashFoundation/zcash_script/issues/35. +We also need to patch the zcash source to enable Windows compatibility. This +is done by applying a patch file as described below. If the patch application +fails, check the patch file for reference on what needs to be changed (and +update the patch file). + If you need to update the zcash source, run: ```console @@ -54,6 +59,7 @@ git rm -r depend/zcash (commit changes) git subtree add -P depend/zcash https://github.com/zcash/zcash.git --squash git rm depend/zcash/Cargo.toml +git apply zcash.patch (commit changes) ``` diff --git a/build.rs b/build.rs index 4d6589056..e4b85cc89 100644 --- a/build.rs +++ b/build.rs @@ -32,7 +32,7 @@ fn bindgen_headers() -> Result<()> { .header("depend/zcash/src/script/zcash_script.h") // Tell cargo to invalidate the built crate whenever any of the // included header files changed. - .parse_callbacks(Box::new(bindgen::CargoCallbacks)) + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) // Finish the builder and generate the bindings. .generate() .map_err(|_| Error::GenerateBindings)?; @@ -115,7 +115,7 @@ fn gen_cxxbridge() -> Result<()> { fs::create_dir_all(header_path.parent().unwrap()).unwrap(); fs::write(header_path, output.header).unwrap(); - let src_path = src_out_path.join(format!("{}.c", filename)); + let src_path = src_out_path.join(format!("{}.cpp", filename)); // Create output dir if does not exist (since `filename` can have a subdir) fs::create_dir_all(src_path.parent().unwrap()).unwrap(); fs::write(src_path, output.implementation).unwrap(); @@ -203,10 +203,12 @@ fn main() -> Result<()> { base_config .file("depend/zcash/src/script/zcash_script.cpp") .file("depend/zcash/src/util/strencodings.cpp") + .file("depend/zcash/src/amount.cpp") .file("depend/zcash/src/uint256.cpp") .file("depend/zcash/src/pubkey.cpp") .file("depend/zcash/src/hash.cpp") .file("depend/zcash/src/streams_rust.cpp") + .file("depend/zcash/src/zip317.cpp") .file("depend/zcash/src/primitives/transaction.cpp") .file("depend/zcash/src/crypto/ripemd160.cpp") .file("depend/zcash/src/crypto/sha1.cpp") @@ -217,11 +219,12 @@ fn main() -> Result<()> { .file("depend/zcash/src/script/script.cpp") .file("depend/zcash/src/script/script_error.cpp") .file("depend/zcash/src/support/cleanse.cpp") + .file("depend/zcash/src/zcash/cache.cpp") // A subset of the files generated by gen_cxxbridge // which are required by zcash_script. - .file(gen_path.join("src/blake2b.c")) - .file(gen_path.join("src/bridge.c")) - .file(gen_path.join("src/streams.c")) + .file(gen_path.join("src/blake2b.cpp")) + .file(gen_path.join("src/bridge.cpp")) + .file(gen_path.join("src/streams.cpp")) .compile("libzcash_script.a"); Ok(()) diff --git a/depend/zcash/src/zcash/cache.cpp b/depend/zcash/src/zcash/cache.cpp index c5cd6b173..1da334b37 100644 --- a/depend/zcash/src/zcash/cache.cpp +++ b/depend/zcash/src/zcash/cache.cpp @@ -3,7 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "zcash/cache.h" -#include "util/system.h" +// #include "util/system.h" namespace libzcash { @@ -11,8 +11,8 @@ std::unique_ptr NewBundleValidityCache(rust::Str kind, size { auto cache = std::unique_ptr(new BundleValidityCache()); size_t nElems = cache->setup_bytes(nMaxCacheSize); - LogPrintf("Using %zu MiB out of %zu requested for %s bundle cache, able to store %zu elements\n", - (nElems * sizeof(BundleCacheEntry)) >> 20, nMaxCacheSize >> 20, kind, nElems); + // LogPrintf("Using %zu MiB out of %zu requested for %s bundle cache, able to store %zu elements\n", + // (nElems * sizeof(BundleCacheEntry)) >> 20, nMaxCacheSize >> 20, kind, nElems); return cache; } } // namespace libzcash diff --git a/depend/zcash/src/zcash/cache.h b/depend/zcash/src/zcash/cache.h index 9bef1e43b..19eab093f 100644 --- a/depend/zcash/src/zcash/cache.h +++ b/depend/zcash/src/zcash/cache.h @@ -31,7 +31,7 @@ class BundleCacheHasher { static_assert(hash_select < 8, "BundleCacheHasher only has 8 hashes available."); uint32_t u; - std::memcpy(&u, key.begin() + 4 * hash_select, 4); + std::memcpy(&u, key.data() + 4 * hash_select, 4); return u; } }; diff --git a/zcash.patch b/zcash.patch new file mode 100644 index 000000000..abd5641b3 --- /dev/null +++ b/zcash.patch @@ -0,0 +1,37 @@ +diff --git a/depend/zcash/src/zcash/cache.cpp b/depend/zcash/src/zcash/cache.cpp +index c5cd6b173c..1da334b377 100644 +--- a/depend/zcash/src/zcash/cache.cpp ++++ b/depend/zcash/src/zcash/cache.cpp +@@ -3,7 +3,7 @@ + // file COPYING or http://www.opensource.org/licenses/mit-license.php. + + #include "zcash/cache.h" +-#include "util/system.h" ++// #include "util/system.h" + + namespace libzcash + { +@@ -11,8 +11,8 @@ std::unique_ptr NewBundleValidityCache(rust::Str kind, size + { + auto cache = std::unique_ptr(new BundleValidityCache()); + size_t nElems = cache->setup_bytes(nMaxCacheSize); +- LogPrintf("Using %zu MiB out of %zu requested for %s bundle cache, able to store %zu elements\n", +- (nElems * sizeof(BundleCacheEntry)) >> 20, nMaxCacheSize >> 20, kind, nElems); ++ // LogPrintf("Using %zu MiB out of %zu requested for %s bundle cache, able to store %zu elements\n", ++ // (nElems * sizeof(BundleCacheEntry)) >> 20, nMaxCacheSize >> 20, kind, nElems); + return cache; + } + } // namespace libzcash +diff --git a/depend/zcash/src/zcash/cache.h b/depend/zcash/src/zcash/cache.h +index 9bef1e43b5..283123bec9 100644 +--- a/depend/zcash/src/zcash/cache.h ++++ b/depend/zcash/src/zcash/cache.h +@@ -31,7 +31,7 @@ public: + { + static_assert(hash_select < 8, "BundleCacheHasher only has 8 hashes available."); + uint32_t u; +- std::memcpy(&u, key.begin() + 4 * hash_select, 4); ++ std::memcpy(&u, key.data() + 4 * hash_select, 4); + return u; + } + };