Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore Windows support with MSVC #108

Merged
merged 5 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down
46 changes: 35 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ 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
git rm -r depend/zcash
(commit changes)
git subtree add -P depend/zcash https://github.com/zcash/zcash.git <ref> --squash
git rm depend/zcash/Cargo.toml
git apply zcash.patch
(commit changes)
```

Expand Down
13 changes: 8 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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")
Expand All @@ -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(())
Expand Down
6 changes: 3 additions & 3 deletions depend/zcash/src/zcash/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "zcash/cache.h"
#include "util/system.h"
// #include "util/system.h"
oxarbitrage marked this conversation as resolved.
Show resolved Hide resolved

namespace libzcash
{
std::unique_ptr<BundleValidityCache> NewBundleValidityCache(rust::Str kind, size_t nMaxCacheSize)
{
auto cache = std::unique_ptr<BundleValidityCache>(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);
oxarbitrage marked this conversation as resolved.
Show resolved Hide resolved
return cache;
}
} // namespace libzcash
Expand Down
2 changes: 1 addition & 1 deletion depend/zcash/src/zcash/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down
37 changes: 37 additions & 0 deletions zcash.patch
Original file line number Diff line number Diff line change
@@ -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<BundleValidityCache> NewBundleValidityCache(rust::Str kind, size
{
auto cache = std::unique_ptr<BundleValidityCache>(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;
}
};
Loading