Switched to using a *much* simpler build-script

This commit is contained in:
Brooks J Rady 2021-02-16 18:33:27 +00:00
parent 5a3caba55f
commit bdfec65cfb
5 changed files with 39 additions and 115 deletions

19
build-all.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
# This is temporary while https://github.com/rust-lang/cargo/issues/7004 is open
echo "Building zellij-tile (1/5)..."
cd zellij-tile
cargo build --release
echo "Building status-bar (2/5)..."
cd ../default-tiles/status-bar
cargo build --release
echo "Building strider (3/5)..."
cd ../strider
cargo build --release
echo "Optimising WASM executables (4/5)..."
cd ../..
wasm-opt -O target/wasm32-wasi/release/status-bar.wasm -o assets/plugins/status-bar.wasm
wasm-opt -O target/wasm32-wasi/release/strider.wasm -o assets/plugins/strider.wasm
echo "Building zellij (5/5)..."
cargo build $@

130
build.rs
View File

@ -1,7 +1,6 @@
use directories_next::ProjectDirs;
use std::{env::*, fs, path::Path, process::Command};
use std::fs;
use structopt::clap::Shell;
use toml::Value;
use walkdir::WalkDir;
include!("src/cli.rs");
@ -9,117 +8,6 @@ include!("src/cli.rs");
const BIN_NAME: &str = "zellij";
fn main() {
// Build Sub-Projects (Temporary?)
for entry in WalkDir::new(".") {
let entry = entry.unwrap();
let ext = entry.path().extension();
if ext.is_some() && ext.unwrap() == "rs" {
println!("cargo:rerun-if-changed={}", entry.path().to_string_lossy());
}
}
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let manifest: Value =
toml::from_str(&fs::read_to_string(manifest_dir.join("Cargo.toml")).unwrap()).unwrap();
let members = manifest
.get("workspace")
.unwrap()
.get("members")
.unwrap()
.as_array()
.unwrap();
let release = if var("PROFILE").unwrap() == "release" {
"--release"
} else {
""
};
let starting_dir = current_dir().unwrap();
let alt_target = manifest_dir.join("target/tiles");
for project in members {
let path = manifest_dir.join(project.as_str().unwrap());
// Should be able to change directory to continue build process
set_current_dir(&path).unwrap();
// FIXME: This is soul-crushingly terrible, but I can't keep the values alive long enough
if var("PROFILE").unwrap() == "release" {
Command::new("cargo".to_string())
.arg("build")
.arg("--target-dir")
.arg(&alt_target.as_os_str())
.arg("--release")
.status()
.unwrap();
} else {
Command::new("cargo")
.arg("build")
.arg("--target-dir")
.arg(&alt_target.as_os_str())
.status()
.unwrap();
}
}
// Should be able to change directory to continue build process
set_current_dir(&starting_dir).unwrap();
if var("PROFILE").unwrap() == "release" {
// FIXME: Deduplicate this with the initial walk all .rs pattern
for entry in fs::read_dir(alt_target.join("wasm32-wasi/release/")).unwrap() {
let entry = entry.unwrap().path();
let ext = entry.extension();
if ext.is_some() && ext.unwrap() == "wasm" {
dbg!(&entry);
Command::new("wasm-opt")
.arg("-O")
.arg(entry.as_os_str())
.arg("-o")
.arg(format!(
"assets/plugins/{}",
entry.file_name().unwrap().to_string_lossy()
))
.status()
.unwrap_or_else(|_| {
Command::new("cp")
.arg(entry.as_os_str())
.arg(format!(
"assets/plugins/{}",
entry.file_name().unwrap().to_string_lossy()
))
.status()
.unwrap()
});
}
}
} else {
// FIXME: Deduplicate this with the initial walk all .rs pattern
for entry in fs::read_dir(alt_target.join("wasm32-wasi/debug/")).unwrap() {
let entry = entry.unwrap().path();
let ext = entry.extension();
if ext.is_some() && ext.unwrap() == "wasm" {
dbg!(&entry);
Command::new("wasm-opt")
.arg("-O")
.arg(entry.as_os_str())
.arg("-o")
.arg(format!(
"assets/plugins/{}",
entry.file_name().unwrap().to_string_lossy()
))
.status()
.unwrap_or_else(|_| {
Command::new("cp")
.arg(entry.as_os_str())
.arg(format!(
"assets/plugins/{}",
entry.file_name().unwrap().to_string_lossy()
))
.status()
.unwrap()
});
}
}
}
// Generate Shell Completions
let mut clap_app = CliArgs::clap();
println!("cargo:rerun-if-changed=src/cli.rs");
@ -134,4 +22,20 @@ fn main() {
clap_app.gen_completions(BIN_NAME, Shell::Bash, &out_dir);
clap_app.gen_completions(BIN_NAME, Shell::Zsh, &out_dir);
clap_app.gen_completions(BIN_NAME, Shell::Fish, &out_dir);
// Clear Default Plugins and Layouts
for entry in WalkDir::new("assets/") {
let entry = entry.unwrap();
let ext = entry.path().extension();
if ext.is_some() && ext.unwrap() == "rs" {
println!("cargo:rerun-if-changed={}", entry.path().to_string_lossy());
}
}
let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
let data_dir = project_dirs.data_dir();
drop(fs::remove_file(data_dir.join("plugins/status-bar.wasm")));
drop(fs::remove_file(data_dir.join("plugins/strider.wasm")));
drop(fs::remove_file(data_dir.join("layouts/default.yaml")));
drop(fs::remove_file(data_dir.join("layouts/strider.yaml")));
}

View File

@ -3,4 +3,4 @@ pub mod layout;
pub mod panes;
pub mod tab;
pub fn start_client() {}
pub fn _start_client() {}

View File

@ -38,7 +38,7 @@ pub enum ClientToServerMsg {
// Types of messages sent from the server to the client
// @@@ Implement Serialize and Deserialize for this...
pub enum ServerToClientMsg {
pub enum _ServerToClientMsg {
// Info about a particular session
SessionInfo(Session),
// A list of sessions

View File

@ -417,6 +417,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
let project_dirs =
ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
let plugin_dir = project_dirs.data_dir().join("plugins/");
// FIXME: This really shouldn't need to exist anymore, let's get rid of it!
let root_plugin_dir = Path::new(ZELLIJ_ROOT_PLUGIN_DIR);
let wasm_bytes = fs::read(&path)
.or_else(|_| fs::read(&path.with_extension("wasm")))