Skip to content

Commit 992162d

Browse files
authored
ci: build startup.js on cargo build (dprint#30)
1 parent 4687994 commit 992162d

File tree

7 files changed

+47
-240384
lines changed

7 files changed

+47
-240384
lines changed

.github/workflows/ci.yml

+7
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,19 @@ jobs:
3838
- uses: actions/checkout@v2
3939
- uses: dtolnay/rust-toolchain@stable
4040
- uses: Swatinem/rust-cache@v1
41+
- uses: denoland/setup-deno@v1
42+
43+
- name: npm install
44+
run: cd js/node && npm ci
4145

4246
# Build
4347
- name: Build release
4448
if: matrix.config.kind == 'test_release'
4549
run: cargo build --release
4650

51+
- name: Test snapshot
52+
run: deno task test
53+
4754
- name: Test release
4855
if: matrix.config.kind == 'test_release'
4956
run: cargo test --release

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
js/node/node_modules
22
js/node/dist
3+
js/startup.js
34
target

build.rs

+34-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use std::env;
55
use std::path::Path;
66
use std::path::PathBuf;
7+
use std::process::Command;
78

89
use deno_core::include_js_files;
910
use deno_core::serde_v8;
@@ -16,15 +17,44 @@ fn main() {
1617
let c = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
1718
let o = PathBuf::from(env::var_os("OUT_DIR").unwrap());
1819
let startup_snapshot_path = o.join("STARTUP_SNAPSHOT.bin");
19-
let startup_code_path = c.join("js").join("startup.js");
20+
let js_dir = c.join("js");
21+
let js_src_dir = js_dir.join("src");
22+
let startup_code_path = js_dir.join("startup.js");
2023
let supported_extensions_path = o.join("SUPPORTED_EXTENSIONS.json");
2124

22-
// ensure the build is invalidated if the startup file changes
23-
println!("cargo:rerun-if-changed={}", startup_code_path.display());
25+
let status = Command::new("deno")
26+
.args(["task", "build"])
27+
.status()
28+
.unwrap();
29+
if status.code() != Some(0) {
30+
panic!("Error building.");
31+
}
32+
33+
// ensure the build is invalidated if any of these files change
34+
println!(
35+
"cargo:rerun-if-changed={}",
36+
js_src_dir.join("main.ts").display()
37+
);
38+
println!(
39+
"cargo:rerun-if-changed={}",
40+
js_src_dir.join("package.json").display()
41+
);
42+
println!(
43+
"cargo:rerun-if-changed={}",
44+
js_src_dir.join("package-lock.json").display()
45+
);
46+
println!(
47+
"cargo:rerun-if-changed={}",
48+
js_src_dir.join("shims/node-shim.js").display()
49+
);
50+
println!(
51+
"cargo:rerun-if-changed={}",
52+
js_src_dir.join("shims/url.js").display()
53+
);
54+
2455
let mut js_runtime = get_runtime(&startup_code_path, true);
2556
let snapshot = js_runtime.snapshot();
2657
let snapshot_slice: &[u8] = &*snapshot;
27-
println!("Snapshot size: {}", snapshot_slice.len());
2858

2959
let compressed_snapshot_with_size = {
3060
let mut vec = vec![];
@@ -42,13 +72,7 @@ fn main() {
4272
vec
4373
};
4474

45-
println!(
46-
"Snapshot compressed size: {}",
47-
compressed_snapshot_with_size.len()
48-
);
49-
5075
std::fs::write(&startup_snapshot_path, compressed_snapshot_with_size).unwrap();
51-
println!("Snapshot written to: {} ", startup_snapshot_path.display());
5276

5377
// serialize the supported extensions
5478
let mut js_runtime = get_runtime(&startup_code_path, false); // panics otherwise

deno.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"tasks": {
33
"build": "cd js/node && npm run build:script",
4-
"test": "deno test --no-check js/startup.test.ts"
4+
"test": "cargo build && deno test --no-check js/startup.test.ts"
55
}
66
}

0 commit comments

Comments
 (0)