Skip to content

Commit cf9e0d2

Browse files
Restore Windows support with MSVC (#108)
* switch to MSVC, fixes to support it * fix linking errors * document how to patch zcash source * update hash due to nightly breakage; don't use deprecated bindgen function * update patch with str4d's upstream suggestion --------- Co-authored-by: Alfredo Garcia <[email protected]>
1 parent 6c2eb13 commit cf9e0d2

File tree

7 files changed

+93
-29
lines changed

7 files changed

+93
-29
lines changed

.github/workflows/ci.yml

+3-9
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
strategy:
7575
matrix:
7676
# "windows-latest" was removed; see https://github.com/ZcashFoundation/zcash_script/issues/38
77-
os: [ubuntu-latest, macOS-latest]
77+
os: [ubuntu-latest, macOS-latest, windows-latest]
7878
steps:
7979
- uses: actions/checkout@v4
8080
with:
@@ -85,16 +85,10 @@ jobs:
8585
# - name: install LLVM on Mac
8686
# if: matrix.os == 'macOS-latest'
8787
# run: brew install llvm
88-
- name: install LLVM on Windows
89-
if: matrix.os == 'windows-latest'
90-
run: |
91-
choco install llvm -y
92-
echo "C:\Program Files\LLVM\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
93-
echo "LIBCLANG_PATH=C:\Program Files\LLVM\bin" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
9488
- uses: actions-rs/toolchain@v1
9589
if: matrix.os == 'windows-latest'
9690
with:
97-
target: x86_64-pc-windows-gnu
91+
target: x86_64-pc-windows-msvc
9892
toolchain: stable
9993
profile: minimal
10094
override: true
@@ -108,7 +102,7 @@ jobs:
108102
if: matrix.os == 'windows-latest'
109103
with:
110104
command: test
111-
args: --target x86_64-pc-windows-gnu
105+
args: --target x86_64-pc-windows-msvc
112106
- uses: actions-rs/cargo@v1
113107
if: matrix.os != 'windows-latest'
114108
with:

Cargo.lock

+35-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,19 @@ work correctly. Since we don't allow those in our repository, we start over
4747
every time, basically using it as a glorified `git clone`. This issue is being
4848
tracked in https://github.com/ZcashFoundation/zcash_script/issues/35.
4949

50+
We also need to patch the zcash source to enable Windows compatibility. This
51+
is done by applying a patch file as described below. If the patch application
52+
fails, check the patch file for reference on what needs to be changed (and
53+
update the patch file).
54+
5055
If you need to update the zcash source, run:
5156

5257
```console
5358
git rm -r depend/zcash
5459
(commit changes)
5560
git subtree add -P depend/zcash https://github.com/zcash/zcash.git <ref> --squash
5661
git rm depend/zcash/Cargo.toml
62+
git apply zcash.patch
5763
(commit changes)
5864
```
5965

build.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn bindgen_headers() -> Result<()> {
3232
.header("depend/zcash/src/script/zcash_script.h")
3333
// Tell cargo to invalidate the built crate whenever any of the
3434
// included header files changed.
35-
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
35+
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
3636
// Finish the builder and generate the bindings.
3737
.generate()
3838
.map_err(|_| Error::GenerateBindings)?;
@@ -115,7 +115,7 @@ fn gen_cxxbridge() -> Result<()> {
115115
fs::create_dir_all(header_path.parent().unwrap()).unwrap();
116116
fs::write(header_path, output.header).unwrap();
117117

118-
let src_path = src_out_path.join(format!("{}.c", filename));
118+
let src_path = src_out_path.join(format!("{}.cpp", filename));
119119
// Create output dir if does not exist (since `filename` can have a subdir)
120120
fs::create_dir_all(src_path.parent().unwrap()).unwrap();
121121
fs::write(src_path, output.implementation).unwrap();
@@ -203,10 +203,12 @@ fn main() -> Result<()> {
203203
base_config
204204
.file("depend/zcash/src/script/zcash_script.cpp")
205205
.file("depend/zcash/src/util/strencodings.cpp")
206+
.file("depend/zcash/src/amount.cpp")
206207
.file("depend/zcash/src/uint256.cpp")
207208
.file("depend/zcash/src/pubkey.cpp")
208209
.file("depend/zcash/src/hash.cpp")
209210
.file("depend/zcash/src/streams_rust.cpp")
211+
.file("depend/zcash/src/zip317.cpp")
210212
.file("depend/zcash/src/primitives/transaction.cpp")
211213
.file("depend/zcash/src/crypto/ripemd160.cpp")
212214
.file("depend/zcash/src/crypto/sha1.cpp")
@@ -217,11 +219,12 @@ fn main() -> Result<()> {
217219
.file("depend/zcash/src/script/script.cpp")
218220
.file("depend/zcash/src/script/script_error.cpp")
219221
.file("depend/zcash/src/support/cleanse.cpp")
222+
.file("depend/zcash/src/zcash/cache.cpp")
220223
// A subset of the files generated by gen_cxxbridge
221224
// which are required by zcash_script.
222-
.file(gen_path.join("src/blake2b.c"))
223-
.file(gen_path.join("src/bridge.c"))
224-
.file(gen_path.join("src/streams.c"))
225+
.file(gen_path.join("src/blake2b.cpp"))
226+
.file(gen_path.join("src/bridge.cpp"))
227+
.file(gen_path.join("src/streams.cpp"))
225228
.compile("libzcash_script.a");
226229

227230
Ok(())

depend/zcash/src/zcash/cache.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include "zcash/cache.h"
6-
#include "util/system.h"
6+
// #include "util/system.h"
77

88
namespace libzcash
99
{
1010
std::unique_ptr<BundleValidityCache> NewBundleValidityCache(rust::Str kind, size_t nMaxCacheSize)
1111
{
1212
auto cache = std::unique_ptr<BundleValidityCache>(new BundleValidityCache());
1313
size_t nElems = cache->setup_bytes(nMaxCacheSize);
14-
LogPrintf("Using %zu MiB out of %zu requested for %s bundle cache, able to store %zu elements\n",
15-
(nElems * sizeof(BundleCacheEntry)) >> 20, nMaxCacheSize >> 20, kind, nElems);
14+
// LogPrintf("Using %zu MiB out of %zu requested for %s bundle cache, able to store %zu elements\n",
15+
// (nElems * sizeof(BundleCacheEntry)) >> 20, nMaxCacheSize >> 20, kind, nElems);
1616
return cache;
1717
}
1818
} // namespace libzcash

depend/zcash/src/zcash/cache.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class BundleCacheHasher
3131
{
3232
static_assert(hash_select < 8, "BundleCacheHasher only has 8 hashes available.");
3333
uint32_t u;
34-
std::memcpy(&u, key.begin() + 4 * hash_select, 4);
34+
std::memcpy(&u, key.data() + 4 * hash_select, 4);
3535
return u;
3636
}
3737
};

zcash.patch

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
diff --git a/depend/zcash/src/zcash/cache.cpp b/depend/zcash/src/zcash/cache.cpp
2+
index c5cd6b173c..1da334b377 100644
3+
--- a/depend/zcash/src/zcash/cache.cpp
4+
+++ b/depend/zcash/src/zcash/cache.cpp
5+
@@ -3,7 +3,7 @@
6+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
7+
8+
#include "zcash/cache.h"
9+
-#include "util/system.h"
10+
+// #include "util/system.h"
11+
12+
namespace libzcash
13+
{
14+
@@ -11,8 +11,8 @@ std::unique_ptr<BundleValidityCache> NewBundleValidityCache(rust::Str kind, size
15+
{
16+
auto cache = std::unique_ptr<BundleValidityCache>(new BundleValidityCache());
17+
size_t nElems = cache->setup_bytes(nMaxCacheSize);
18+
- LogPrintf("Using %zu MiB out of %zu requested for %s bundle cache, able to store %zu elements\n",
19+
- (nElems * sizeof(BundleCacheEntry)) >> 20, nMaxCacheSize >> 20, kind, nElems);
20+
+ // LogPrintf("Using %zu MiB out of %zu requested for %s bundle cache, able to store %zu elements\n",
21+
+ // (nElems * sizeof(BundleCacheEntry)) >> 20, nMaxCacheSize >> 20, kind, nElems);
22+
return cache;
23+
}
24+
} // namespace libzcash
25+
diff --git a/depend/zcash/src/zcash/cache.h b/depend/zcash/src/zcash/cache.h
26+
index 9bef1e43b5..283123bec9 100644
27+
--- a/depend/zcash/src/zcash/cache.h
28+
+++ b/depend/zcash/src/zcash/cache.h
29+
@@ -31,7 +31,7 @@ public:
30+
{
31+
static_assert(hash_select < 8, "BundleCacheHasher only has 8 hashes available.");
32+
uint32_t u;
33+
- std::memcpy(&u, key.begin() + 4 * hash_select, 4);
34+
+ std::memcpy(&u, key.data() + 4 * hash_select, 4);
35+
return u;
36+
}
37+
};

0 commit comments

Comments
 (0)