Skip to content

Commit

Permalink
Change snapshot path
Browse files Browse the repository at this point in the history
  • Loading branch information
max-lt committed Mar 23, 2024
1 parent d0fd8ef commit 714fdce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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");
println!("cargo:rerun-if-changed=src/ext/*");
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();
}
}
}
5 changes: 3 additions & 2 deletions src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit 714fdce

Please sign in to comment.