Skip to content

Commit aa1b24e

Browse files
feat(arbitrator): use build.rs to build brotli
1 parent a64bcc4 commit aa1b24e

File tree

7 files changed

+62
-3
lines changed

7 files changed

+62
-3
lines changed

arbitrator/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

arbitrator/brotli/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ num_enum.workspace = true
1414
wasmer = { path = "../tools/wasmer/lib/api", optional = true }
1515
wee_alloc.workspace = true
1616

17+
[build-dependencies]
18+
cc = { version = "1.0", optional = true }
19+
1720
[lib]
1821
crate-type = ["lib"]
1922

2023
[features]
2124
wasmer_traits = ["dep:wasmer"]
25+
cc_brotli = ["dep:cc"]

arbitrator/brotli/build.rs

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright 2021-2024, Offchain Labs, Inc.
22
// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE.md
3-
4-
use std::env;
5-
3+
#[cfg(not(feature = "cc_brotli"))]
64
fn main() {
5+
use std::env;
6+
77
let target_arch = env::var("TARGET").unwrap();
88

99
if target_arch.contains("wasm32") {
@@ -16,3 +16,53 @@ fn main() {
1616
println!("cargo:rustc-link-lib=static=brotlidec-static");
1717
println!("cargo:rustc-link-lib=static=brotlicommon-static");
1818
}
19+
20+
#[cfg(feature = "cc_brotli")]
21+
fn main() {
22+
use std::env;
23+
use std::path::PathBuf;
24+
let manifest_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
25+
let include_dir = manifest_dir.join("../../brotli/c/include");
26+
cc::Build::new()
27+
.files(&[
28+
"../../brotli/c/common/constants.c",
29+
"../../brotli/c/common/context.c",
30+
"../../brotli/c/common/dictionary.c",
31+
"../../brotli/c/common/platform.c",
32+
"../../brotli/c/common/shared_dictionary.c",
33+
"../../brotli/c/common/transform.c",
34+
"../../brotli/c/dec/bit_reader.c",
35+
"../../brotli/c/dec/decode.c",
36+
"../../brotli/c/dec/huffman.c",
37+
"../../brotli/c/dec/state.c",
38+
"../../brotli/c/enc/backward_references.c",
39+
"../../brotli/c/enc/backward_references_hq.c",
40+
"../../brotli/c/enc/bit_cost.c",
41+
"../../brotli/c/enc/block_splitter.c",
42+
"../../brotli/c/enc/brotli_bit_stream.c",
43+
"../../brotli/c/enc/cluster.c",
44+
"../../brotli/c/enc/command.c",
45+
"../../brotli/c/enc/compound_dictionary.c",
46+
"../../brotli/c/enc/compress_fragment.c",
47+
"../../brotli/c/enc/compress_fragment_two_pass.c",
48+
"../../brotli/c/enc/dictionary_hash.c",
49+
"../../brotli/c/enc/encode.c",
50+
"../../brotli/c/enc/encoder_dict.c",
51+
"../../brotli/c/enc/entropy_encode.c",
52+
"../../brotli/c/enc/fast_log.c",
53+
"../../brotli/c/enc/histogram.c",
54+
"../../brotli/c/enc/literal_cost.c",
55+
"../../brotli/c/enc/memory.c",
56+
"../../brotli/c/enc/metablock.c",
57+
"../../brotli/c/enc/static_dict.c",
58+
"../../brotli/c/enc/utf8_util.c",
59+
])
60+
.includes(["../../brotli/c/include"])
61+
.define("BROTLI_BUILD_ENC_EXTRA_API", None)
62+
.define("BROTLI_HAVE_LOG2", "1")
63+
.warnings(false)
64+
.compile("brotli");
65+
66+
println!("cargo:include={}", include_dir.display());
67+
println!("cargo:rerun-if-changed=brotli/c");
68+
}

arbitrator/caller-env/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ default = ["brotli"]
1515
brotli = ["dep:brotli"]
1616
static_caller = []
1717
wasmer_traits = ["dep:wasmer", "brotli?/wasmer_traits"]
18+
cc_brotli = ["brotli?/cc_brotli"]

arbitrator/jit/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ sha2 = "0.9.9"
2525

2626
[features]
2727
llvm = ["dep:wasmer-compiler-llvm"]
28+
cc_brotli = ["brotli/cc_brotli"]

arbitrator/prover/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@ counters = []
6161
native = ["dep:wasmer", "dep:wasmer-compiler-singlepass", "brotli/wasmer_traits", "dep:c-kzg"]
6262
singlepass_rayon = ["wasmer-compiler-singlepass?/rayon"]
6363
rayon = ["dep:rayon"]
64+
cc_brotli = ["brotli/cc_brotli"]

arbitrator/stylus/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ benchmark = []
3737
timings = []
3838
singlepass_rayon = ["prover/singlepass_rayon", "wasmer-compiler-singlepass/rayon"]
3939
rayon = ["prover/rayon"]
40+
cc_brotli = ["brotli/cc_brotli"]
4041

4142
[lib]
4243
crate-type = ["lib", "staticlib"]

0 commit comments

Comments
 (0)