From 8843b8c96172243f9da71a8a8aabec0a5d043afa Mon Sep 17 00:00:00 2001 From: max-lt Date: Mon, 26 Feb 2024 07:51:43 +0100 Subject: [PATCH] Use build.rs to generate empty snapshot --- .github/workflows/rust.yml | 2 -- build.rs | 19 +++++++++++++++++++ src/runtime.rs | 2 +- src/snapshot.rs | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 build.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 29c48f9..092e701 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -14,8 +14,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Prebuild - run: touch RUNTIME_SNAPSHOT.bin - name: Build run: cargo build --verbose - name: Run tests diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..bc00f6d --- /dev/null +++ b/build.rs @@ -0,0 +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"); + +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); + + // 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/runtime.rs b/src/runtime.rs index 841566b..aeab006 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -20,7 +20,7 @@ use log::debug; const USER_AGENT: &str = "OpenWorkers/0.1.0"; static RUNTIME_SNAPSHOT: &[u8] = - include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/RUNTIME_SNAPSHOT.bin")); + include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/target/RUNTIME_SNAPSHOT.bin")); pub fn module_url(path_str: &str) -> Url { let current_dir = std::env::current_dir().unwrap(); diff --git a/src/snapshot.rs b/src/snapshot.rs index 0487d2e..1a42553 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -9,7 +9,7 @@ use std::env; use std::path::PathBuf; use std::fs::File; -const RUNTIME_SNAPSHOT_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/RUNTIME_SNAPSHOT.bin"); +const RUNTIME_SNAPSHOT_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/target/RUNTIME_SNAPSHOT.bin"); pub fn create_runtime_snapshot() { println!("Building snapshot");