Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 4d1f816

Browse files
authored
token-cli: Make BPF program builds in build.rs dependent on env var (#3362)
* token-cli: Make BPF program build dependent on env var * Do it during `build` and not `test`
1 parent 04954d0 commit 4d1f816

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

ci/cargo-build-test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ set -x
1515
make -C examples/c
1616

1717
# Build/test all host crates
18-
cargo +"$rust_stable" build
18+
BUILD_DEPENDENT_PROGRAMS=1 cargo +"$rust_stable" build
1919
cargo +"$rust_stable" test -- --nocapture
2020

2121
# Run test-client sanity check

token/cli/build.rs

+27-25
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,34 @@ fn build_bpf(program_directory: &Path) {
4646
}
4747

4848
fn main() {
49-
if let Ok(debug) = env::var("DEBUG") {
50-
if debug == "true" {
51-
let cwd = env::current_dir().expect("Unable to get current working directory");
52-
let spl_token_2022_dir = cwd
53-
.parent()
54-
.expect("Unable to get parent directory of current working dir")
55-
.join("program-2022");
56-
rerun_if_changed(&spl_token_2022_dir);
57-
let spl_token_dir = cwd
58-
.parent()
59-
.expect("Unable to get parent directory of current working dir")
60-
.join("program");
61-
rerun_if_changed(&spl_token_dir);
62-
let spl_associated_token_account_dir = cwd
63-
.parent()
64-
.expect("Unable to get parent directory of current working dir")
65-
.parent()
66-
.expect("Unable to get parent directory of current working dir")
67-
.join("associated-token-account")
68-
.join("program");
69-
rerun_if_changed(&spl_associated_token_account_dir);
49+
let is_debug = env::var("DEBUG").map(|v| v == "true").unwrap_or(false);
50+
let build_dependent_programs = env::var("BUILD_DEPENDENT_PROGRAMS")
51+
.map(|v| v != "false" && v != "0")
52+
.unwrap_or(false);
53+
if is_debug && build_dependent_programs {
54+
let cwd = env::current_dir().expect("Unable to get current working directory");
55+
let spl_token_2022_dir = cwd
56+
.parent()
57+
.expect("Unable to get parent directory of current working dir")
58+
.join("program-2022");
59+
rerun_if_changed(&spl_token_2022_dir);
60+
let spl_token_dir = cwd
61+
.parent()
62+
.expect("Unable to get parent directory of current working dir")
63+
.join("program");
64+
rerun_if_changed(&spl_token_dir);
65+
let spl_associated_token_account_dir = cwd
66+
.parent()
67+
.expect("Unable to get parent directory of current working dir")
68+
.parent()
69+
.expect("Unable to get parent directory of current working dir")
70+
.join("associated-token-account")
71+
.join("program");
72+
rerun_if_changed(&spl_associated_token_account_dir);
7073

71-
build_bpf(&spl_token_dir);
72-
build_bpf(&spl_token_2022_dir);
73-
build_bpf(&spl_associated_token_account_dir);
74-
}
74+
build_bpf(&spl_token_dir);
75+
build_bpf(&spl_token_2022_dir);
76+
build_bpf(&spl_associated_token_account_dir);
7577
}
7678
println!("cargo:rerun-if-changed=build.rs");
7779
}

0 commit comments

Comments
 (0)