Skip to content

Commit

Permalink
Move snapshot from examples to bin
Browse files Browse the repository at this point in the history
  • Loading branch information
max-lt committed Feb 26, 2024
1 parent 1981336 commit 806e7bf
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,22 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4
- name: Cache
uses: actions/cache@v3
continue-on-error: false
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Snapshot runtime
run: cargo run --release --bin snapshot
- name: Build
run: cargo build --verbose
run: cargo build --release --verbose --all --examples
- name: Run tests
run: cargo test --verbose
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "openworkers-runtime"
version = "0.1.0"
version = "0.1.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
File renamed without changes.
10 changes: 7 additions & 3 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ use deno_core::Snapshot;

use log::debug;

const USER_AGENT: &str = "OpenWorkers/0.1.0";
const USER_AGENT: &str = concat!("OpenWorkers/", env!("CARGO_PKG_VERSION"));

static RUNTIME_SNAPSHOT: &[u8] = include_bytes!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/target/RUNTIME_SNAPSHOT.bin"
));

pub (crate) fn user_agent() -> String {
USER_AGENT.to_string()
}

pub fn module_url(path_str: &str) -> Url {
let current_dir = std::env::current_dir().unwrap();
let current_dir = current_dir.as_path();
Expand All @@ -48,7 +52,7 @@ pub(crate) fn extensions(for_snapshot: bool) -> Vec<deno_core::Extension> {
),
deno_crypto::deno_crypto::init_ops_and_esm(None),
deno_fetch::deno_fetch::init_ops_and_esm::<Permissions>(deno_fetch::Options {
user_agent: USER_AGENT.to_string(),
user_agent: user_agent(),
..Default::default()
}),
// OpenWorkers extensions
Expand Down Expand Up @@ -109,7 +113,7 @@ impl Worker {

// Bootstrap
{
let script = format!("globalThis.bootstrap('{}')", USER_AGENT);
let script = format!("globalThis.bootstrap('{}')", user_agent());
let script = deno_core::ModuleCodeString::from(script);

match js_runtime.execute_script(deno_core::located_script_name!(), script) {
Expand Down

0 comments on commit 806e7bf

Please sign in to comment.