readme: add npm install, build.rs: output_reruns touches files, skips target and ui dirs

This commit is contained in:
dr-frmr 2024-08-14 18:43:23 +03:00
parent 91aef91317
commit ae62b7561e
No known key found for this signature in database
2 changed files with 38 additions and 26 deletions

View File

@ -38,6 +38,10 @@ rustup target add wasm32-wasi
rustup target add wasm32-wasi --toolchain nightly rustup target add wasm32-wasi --toolchain nightly
cargo install cargo-wasi cargo install cargo-wasi
# Install NPM so we can build frontends for "distro" packages.
# https://docs.npmjs.com/downloading-and-installing-node-js-and-npm
# If you want to skip this step, run cargo build with the environment variable SKIP_BUILD_FRONTEND=true
# Build the runtime, along with a number of "distro" Wasm modules. # Build the runtime, along with a number of "distro" Wasm modules.
# The compiled binary will be at `kinode/target/debug/kinode` # The compiled binary will be at `kinode/target/debug/kinode`
# OPTIONAL: --release flag (slower build; faster runtime; binary at `kinode/target/release/kinode`) # OPTIONAL: --release flag (slower build; faster runtime; binary at `kinode/target/release/kinode`)

View File

@ -1,5 +1,4 @@
use std::{ use std::{
collections::HashSet,
fs::{self, File}, fs::{self, File},
io::{BufReader, Cursor, Read, Write}, io::{BufReader, Cursor, Read, Write},
path::{Path, PathBuf}, path::{Path, PathBuf},
@ -9,6 +8,13 @@ use flate2::read::GzDecoder;
use tar::Archive; use tar::Archive;
use zip::write::FileOptions; use zip::write::FileOptions;
macro_rules! p {
($($tokens: tt)*) => {
println!("cargo:warning={}", format!($($tokens)*))
}
}
/// get cargo features to compile packages with
fn get_features() -> String { fn get_features() -> String {
let mut features = "".to_string(); let mut features = "".to_string();
for (key, _) in std::env::vars() { for (key, _) in std::env::vars() {
@ -23,25 +29,30 @@ fn get_features() -> String {
features features
} }
fn output_reruns(dir: &Path, rerun_files: &HashSet<String>) { /// print `cargo:rerun-if-changed=PATH` for each path of interest
fn output_reruns(dir: &Path) {
// Check files individually // Check files individually
if let Ok(entries) = fs::read_dir(dir) { if let Ok(entries) = fs::read_dir(dir) {
for entry in entries.filter_map(|e| e.ok()) { for entry in entries.filter_map(|e| e.ok()) {
let path = entry.path(); let path = entry.path();
if let Some(filename) = path.file_name().and_then(|n| n.to_str()) {
// Check if the current file is in our list of interesting files
if filename == "ui" {
continue;
}
if rerun_files.contains(filename) {
// If so, print a `cargo:rerun-if-changed=PATH` line for it
println!("cargo::rerun-if-changed={}", path.display());
continue;
}
}
if path.is_dir() { if path.is_dir() {
// If the entry is a directory not in rerun_files, recursively walk it if let Some(dirname) = path.file_name().and_then(|n| n.to_str()) {
output_reruns(&path, rerun_files); if dirname == "ui" || dirname == "target" {
// do not prompt a rerun if only UI/build files have changed
continue;
}
// If the entry is a directory not in rerun_files, recursively walk it
output_reruns(&path);
}
} else {
if let Some(filename) = path.file_name().and_then(|n| n.to_str()) {
if filename.ends_with(".zip") || filename.ends_with(".wasm") {
// do not prompt a rerun for compiled outputs
continue;
}
// any other changed file within a package subdir prompts a rerun
println!("cargo::rerun-if-changed={}", path.display());
}
} }
} }
} }
@ -64,7 +75,9 @@ fn untar_gz_file(path: &Path, dest: &Path) -> std::io::Result<()> {
Ok(()) Ok(())
} }
/// fetch .tar.gz of kinode book for docs app
fn get_kinode_book(packages_dir: &Path) -> anyhow::Result<()> { fn get_kinode_book(packages_dir: &Path) -> anyhow::Result<()> {
p!("fetching kinode book .tar.gz");
let rt = tokio::runtime::Runtime::new().unwrap(); let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async { rt.block_on(async {
let releases = kit::boot_fake_node::fetch_releases("kinode-dao", "kinode-book") let releases = kit::boot_fake_node::fetch_releases("kinode-dao", "kinode-book")
@ -153,7 +166,7 @@ fn build_and_zip_package(
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
if std::env::var("SKIP_BUILD_SCRIPT").is_ok() { if std::env::var("SKIP_BUILD_SCRIPT").is_ok() {
println!("Skipping build script"); p!("skipping build script");
return Ok(()); return Ok(());
} }
@ -162,7 +175,7 @@ fn main() -> anyhow::Result<()> {
let packages_dir = pwd.join("packages"); let packages_dir = pwd.join("packages");
if std::env::var("SKIP_BUILD_FRONTEND").is_ok() { if std::env::var("SKIP_BUILD_FRONTEND").is_ok() {
println!("Skipping build frontend"); p!("skipping frontend builds");
} else { } else {
// build core frontends // build core frontends
let core_frontends = vec![ let core_frontends = vec![
@ -186,12 +199,7 @@ fn main() -> anyhow::Result<()> {
get_kinode_book(&packages_dir)?; get_kinode_book(&packages_dir)?;
let rerun_files: HashSet<String> = HashSet::from([ output_reruns(&packages_dir);
"Cargo.lock".to_string(),
"Cargo.toml".to_string(),
"src".to_string(),
]);
output_reruns(&parent_dir, &rerun_files);
let features = get_features(); let features = get_features();
@ -201,14 +209,14 @@ fn main() -> anyhow::Result<()> {
Ok(e) => e.path(), Ok(e) => e.path(),
Err(_) => return None, Err(_) => return None,
}; };
let parent_pkg_path = entry_path.join("pkg"); let child_pkg_path = entry_path.join("pkg");
if !parent_pkg_path.exists() { if !child_pkg_path.exists() {
// don't run on, e.g., `.DS_Store` // don't run on, e.g., `.DS_Store`
return None; return None;
} }
Some(build_and_zip_package( Some(build_and_zip_package(
entry_path.clone(), entry_path.clone(),
parent_pkg_path.to_str().unwrap(), child_pkg_path.to_str().unwrap(),
&features, &features,
)) ))
}) })