Skip to content

Commit

Permalink
Use build.rs to generate empty snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
max-lt committed Feb 26, 2024
1 parent e8b824c commit 8843b8c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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();
}
}
2 changes: 1 addition & 1 deletion src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 8843b8c

Please sign in to comment.