diff --git a/build.rs b/build.rs index bc00f6d..312bbd8 100644 --- a/build.rs +++ b/build.rs @@ -1,8 +1,8 @@ -use std::env; use std::fs::File; use std::path::PathBuf; -const RUNTIME_SNAPSHOT_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/target/RUNTIME_SNAPSHOT.bin"); +const RUNTIME_SNAPSHOT_PATH: Option<&str> = option_env!("RUNTIME_SNAPSHOT_PATH"); +const DEFAULT_SNAPSHOT_PATH: &str = "/tmp/openworkers-runtime-snapshot.bin"; fn main () { println!("cargo:rerun-if-changed=build.rs"); @@ -10,10 +10,10 @@ fn main () { println!("cargo:rerun-if-changed=src/runtime.rs"); println!("cargo:rerun-if-changed=src/extensions.rs"); - let path = PathBuf::from(RUNTIME_SNAPSHOT_PATH); + let path = PathBuf::from(RUNTIME_SNAPSHOT_PATH.unwrap_or(DEFAULT_SNAPSHOT_PATH)); // Create the file if it doesn't exist if !path.exists() { File::create(&path).unwrap(); } -} \ No newline at end of file +} diff --git a/src/snapshot.rs b/src/snapshot.rs index 1a42553..646f66f 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -9,13 +9,14 @@ use std::env; use std::path::PathBuf; use std::fs::File; -const RUNTIME_SNAPSHOT_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/target/RUNTIME_SNAPSHOT.bin"); +const RUNTIME_SNAPSHOT_PATH: Option<&str> = option_env!("RUNTIME_SNAPSHOT_PATH"); +const DEFAULT_SNAPSHOT_PATH: &str = "/tmp/openworkers-runtime-snapshot.bin"; pub fn create_runtime_snapshot() { println!("Building snapshot"); // Build the file path to the snapshot. - let snapshot_path = PathBuf::from(RUNTIME_SNAPSHOT_PATH); + let snapshot_path = PathBuf::from(RUNTIME_SNAPSHOT_PATH.unwrap_or(DEFAULT_SNAPSHOT_PATH)); let serializer: SnapshotFileSerializer = SnapshotFileSerializer::new(File::create(snapshot_path).unwrap());