Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ rustup target add wasm32-wasi
rustup target add wasm32-wasi --toolchain nightly
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.
# The compiled binary will be at `kinode/target/debug/kinode`
# OPTIONAL: --release flag (slower build; faster runtime; binary at `kinode/target/release/kinode`)
Expand Down
56 changes: 32 additions & 24 deletions kinode/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
collections::HashSet,
fs::{self, File},
io::{BufReader, Cursor, Read, Write},
path::{Path, PathBuf},
Expand All @@ -9,6 +8,13 @@ use flate2::read::GzDecoder;
use tar::Archive;
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 {
let mut features = "".to_string();
for (key, _) in std::env::vars() {
Expand All @@ -23,26 +29,31 @@ fn get_features() -> String {
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
if let Ok(entries) = fs::read_dir(dir) {
for entry in entries.filter_map(|e| e.ok()) {
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 path.is_dir() {
if let Some(dirname) = path.file_name().and_then(|n| n.to_str()) {
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);
}
if rerun_files.contains(filename) {
// If so, print a `cargo:rerun-if-changed=PATH` line for it
} 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());
continue;
}
}
if path.is_dir() {
// If the entry is a directory not in rerun_files, recursively walk it
output_reruns(&path, rerun_files);
}
}
}
}
Expand All @@ -64,7 +75,9 @@ fn untar_gz_file(path: &Path, dest: &Path) -> std::io::Result<()> {
Ok(())
}

/// fetch .tar.gz of kinode book for docs app
fn get_kinode_book(packages_dir: &Path) -> anyhow::Result<()> {
p!("fetching kinode book .tar.gz");
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let releases = kit::boot_fake_node::fetch_releases("kinode-dao", "kinode-book")
Expand Down Expand Up @@ -153,7 +166,7 @@ fn build_and_zip_package(

fn main() -> anyhow::Result<()> {
if std::env::var("SKIP_BUILD_SCRIPT").is_ok() {
println!("Skipping build script");
p!("skipping build script");
return Ok(());
}

Expand All @@ -162,7 +175,7 @@ fn main() -> anyhow::Result<()> {
let packages_dir = pwd.join("packages");

if std::env::var("SKIP_BUILD_FRONTEND").is_ok() {
println!("Skipping build frontend");
p!("skipping frontend builds");
} else {
// build core frontends
let core_frontends = vec![
Expand All @@ -186,12 +199,7 @@ fn main() -> anyhow::Result<()> {

get_kinode_book(&packages_dir)?;

let rerun_files: HashSet<String> = HashSet::from([
"Cargo.lock".to_string(),
"Cargo.toml".to_string(),
"src".to_string(),
]);
output_reruns(&parent_dir, &rerun_files);
output_reruns(&packages_dir);

let features = get_features();

Expand All @@ -201,14 +209,14 @@ fn main() -> anyhow::Result<()> {
Ok(e) => e.path(),
Err(_) => return None,
};
let parent_pkg_path = entry_path.join("pkg");
if !parent_pkg_path.exists() {
let child_pkg_path = entry_path.join("pkg");
if !child_pkg_path.exists() {
// don't run on, e.g., `.DS_Store`
return None;
}
Some(build_and_zip_package(
entry_path.clone(),
parent_pkg_path.to_str().unwrap(),
child_pkg_path.to_str().unwrap(),
&features,
))
})
Expand Down