Skip to content

Commit 78a86b0

Browse files
committed
fix cxxbridge code generation
1 parent 07418ff commit 78a86b0

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

build.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,19 @@ fn bindgen_headers() -> Result<()> {
6464
/// (This is in contrast to zcash which generates in `depend/zcash/src/rust/gen/`)
6565
fn gen_cxxbridge() -> Result<()> {
6666
let out_path = env::var("OUT_DIR").map_err(Error::Env)?;
67-
let out_path = PathBuf::from(out_path).join("include");
67+
let out_path = PathBuf::from(out_path).join("gen");
68+
let src_out_path = PathBuf::from(&out_path).join("src");
69+
let header_out_path = PathBuf::from(&out_path).join("include").join("rust");
6870

6971
// These must match `CXXBRIDGE_RS` in depend/zcash/src/Makefile.am
7072
let filenames = ["blake2b", "ed25519", "equihash", "streams", "bridge"];
7173

7274
// The output folder must exist
73-
fs::create_dir_all(out_path.join("rust")).unwrap();
75+
fs::create_dir_all(&src_out_path).unwrap();
76+
fs::create_dir_all(&header_out_path).unwrap();
7477

7578
// Generate the generic header file
76-
fs::write(out_path.join("rust/cxx.h"), cxx_gen::HEADER).unwrap();
79+
fs::write(header_out_path.join("cxx.h"), cxx_gen::HEADER).unwrap();
7780

7881
// Generate the source and header for each bridge file
7982
for filename in filenames {
@@ -100,9 +103,13 @@ fn gen_cxxbridge() -> Result<()> {
100103
)
101104
});
102105

103-
fs::write(out_path.join(format!("rust/{}.h", filename)), output.header).unwrap();
104106
fs::write(
105-
out_path.join(format!("rust/{}.c", filename)),
107+
header_out_path.join(format!("{}.h", filename)),
108+
output.header,
109+
)
110+
.unwrap();
111+
fs::write(
112+
src_out_path.join(format!("{}.c", filename)),
106113
output.implementation,
107114
)
108115
.unwrap();
@@ -114,8 +121,8 @@ fn main() -> Result<()> {
114121
bindgen_headers()?;
115122
gen_cxxbridge()?;
116123

117-
let include_path = env::var("OUT_DIR").map_err(Error::Env)?;
118-
let include_path = PathBuf::from(include_path).join("include");
124+
let gen_path = env::var("OUT_DIR").map_err(Error::Env)?;
125+
let gen_path = PathBuf::from(gen_path).join("gen");
119126

120127
let target = env::var("TARGET").expect("TARGET was not set");
121128
let mut base_config = cc::Build::new();
@@ -126,7 +133,7 @@ fn main() -> Result<()> {
126133
.include("depend/zcash/src/")
127134
.include("depend/zcash/src/rust/include/")
128135
.include("depend/zcash/src/secp256k1/include/")
129-
.include(&include_path)
136+
.include(&gen_path.join("include"))
130137
.flag_if_supported("-Wno-implicit-fallthrough")
131138
.flag_if_supported("-Wno-catch-value")
132139
.flag_if_supported("-Wno-reorder")
@@ -155,6 +162,7 @@ fn main() -> Result<()> {
155162
.file("depend/zcash/src/uint256.cpp")
156163
.file("depend/zcash/src/pubkey.cpp")
157164
.file("depend/zcash/src/hash.cpp")
165+
.file("depend/zcash/src/streams_rust.cpp")
158166
.file("depend/zcash/src/primitives/transaction.cpp")
159167
.file("depend/zcash/src/crypto/ripemd160.cpp")
160168
.file("depend/zcash/src/crypto/sha1.cpp")
@@ -165,7 +173,11 @@ fn main() -> Result<()> {
165173
.file("depend/zcash/src/script/script.cpp")
166174
.file("depend/zcash/src/script/script_error.cpp")
167175
.file("depend/zcash/src/support/cleanse.cpp")
168-
.file(include_path.join("rust/blake2b.c"))
176+
// A subset of the files generated by gen_cxxbridge
177+
// which are required by zcash_script.
178+
.file(gen_path.join("src/blake2b.c"))
179+
.file(gen_path.join("src/bridge.c"))
180+
.file(gen_path.join("src/streams.c"))
169181
.compile("libzcash_script.a");
170182

171183
Ok(())

0 commit comments

Comments
 (0)