Skip to content

Commit 319aa3c

Browse files
committed
Rerun build script if environment variable changes
It is not recompiled, so we need to use the runtime function env::var instead of the compile time option_env!.
1 parent 5111f7b commit 319aa3c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

build.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,16 @@ fn main() {
128128
// create a file with the `PHYSICAL_MEMORY_OFFSET` constant
129129
let file_path = out_dir.join("physical_memory_offset.rs");
130130
let mut file = File::create(file_path).expect("failed to create physical_memory_offset.rs");
131-
let physical_memory_offset = match option_env!("BOOTLOADER_PHYSICAL_MEMORY_OFFSET") {
132-
None => 0o_177777_770_000_000_000_0000u64,
133-
Some(s) => s.parse().expect(
134-
"The `BOOTLOADER_PHYSICAL_MEMORY_OFFSET` environment variable must be an integer.",
131+
let physical_memory_offset = match env::var("BOOTLOADER_PHYSICAL_MEMORY_OFFSET") {
132+
Err(env::VarError::NotPresent) => 0o_177777_770_000_000_000_0000u64,
133+
Err(env::VarError::NotUnicode(_)) => panic!(
134+
"The `BOOTLOADER_PHYSICAL_MEMORY_OFFSET` environment variable must be valid unicode"
135135
),
136+
Ok(s) => s.parse().expect(&format!(
137+
"The `BOOTLOADER_PHYSICAL_MEMORY_OFFSET` environment variable must be an\
138+
integer (is `{}`).",
139+
s
140+
)),
136141
};
137142
file.write_all(
138143
format!(
@@ -151,6 +156,7 @@ fn main() {
151156
);
152157

153158
println!("cargo:rerun-if-env-changed=KERNEL");
159+
println!("cargo:rerun-if-env-changed=BOOTLOADER_PHYSICAL_MEMORY_OFFSET");
154160
println!("cargo:rerun-if-changed={}", kernel.display());
155161
println!("cargo:rerun-if-changed=build.rs");
156162
}

0 commit comments

Comments
 (0)