mirror of
https://github.com/zellij-org/zellij.git
synced 2024-12-18 23:01:47 +03:00
infra(simplify build and install)
Merge pull request #186 from zellij-org/simplify-build-and-install
This commit is contained in:
commit
8be470fbc0
@ -13,6 +13,16 @@ of contributions, and don't want a wall of rules to get in the way of that.
|
||||
Before contributing please read our [Code of Conduct](CODE_OF_CONDUCT.md) which
|
||||
all contributors are expected to adhere to.
|
||||
|
||||
## Building
|
||||
To work around a [Cargo bug][https://github.com/rust-lang/cargo/issues/7004], you'll need to use the included `build-all.sh` script.
|
||||
|
||||
```sh
|
||||
# An unoptimized debug build
|
||||
./build-all.sh
|
||||
# A fully optimized release build
|
||||
./build-all.sh --release
|
||||
```
|
||||
|
||||
## Looking for something to work on?
|
||||
|
||||
If you are new contributor to `Zellij` going through [beginners][good-first-issue]
|
||||
|
@ -3,6 +3,8 @@ name = "zellij"
|
||||
version = "0.1.0"
|
||||
authors = ["Aram Drevekenin <aram@poor.dev>"]
|
||||
edition = "2018"
|
||||
description = "Terminal workspace (WIP)"
|
||||
license = "MIT"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
19
build-all.sh
Executable file
19
build-all.sh
Executable 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 $@
|
137
build.rs
137
build.rs
@ -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");
|
||||
@ -135,19 +23,16 @@ fn main() {
|
||||
clap_app.gen_completions(BIN_NAME, Shell::Zsh, &out_dir);
|
||||
clap_app.gen_completions(BIN_NAME, Shell::Fish, &out_dir);
|
||||
|
||||
// Install Default Plugins and Layouts
|
||||
let assets = vec![
|
||||
"plugins/status-bar.wasm",
|
||||
"plugins/strider.wasm",
|
||||
"layouts/default.yaml",
|
||||
"layouts/strider.yaml",
|
||||
];
|
||||
// Clear Default Plugins and Layouts
|
||||
for entry in WalkDir::new("assets/") {
|
||||
let entry = entry.unwrap();
|
||||
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();
|
||||
fs::create_dir_all(data_dir.join("plugins")).unwrap();
|
||||
fs::create_dir_all(data_dir.join("layouts")).unwrap();
|
||||
for asset in assets {
|
||||
fs::copy(Path::new("assets/").join(asset), data_dir.join(asset))
|
||||
.expect("Failed to copy asset files");
|
||||
}
|
||||
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")));
|
||||
}
|
||||
|
@ -3,4 +3,4 @@ pub mod layout;
|
||||
pub mod panes;
|
||||
pub mod tab;
|
||||
|
||||
pub fn start_client() {}
|
||||
pub fn _start_client() {}
|
||||
|
12
src/common/install.rs
Normal file
12
src/common/install.rs
Normal file
@ -0,0 +1,12 @@
|
||||
#[macro_export]
|
||||
macro_rules! asset_map {
|
||||
($($path:literal),+) => {
|
||||
{
|
||||
let mut assets = std::collections::HashMap::new();
|
||||
$(
|
||||
assets.insert($path, include_bytes!(concat!("../assets/", $path)).to_vec());
|
||||
)+
|
||||
assets
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -1,6 +1,7 @@
|
||||
pub mod command_is_executing;
|
||||
pub mod errors;
|
||||
pub mod input;
|
||||
pub mod install;
|
||||
pub mod ipc;
|
||||
pub mod os_input_output;
|
||||
pub mod pty_bus;
|
||||
@ -416,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")))
|
||||
@ -646,7 +648,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
|
||||
let restore_snapshot = "\u{1b}[?1049l";
|
||||
let goto_start_of_last_line = format!("\u{1b}[{};{}H", full_screen_ws.rows, 1);
|
||||
let goodbye_message = format!(
|
||||
"{}\n{}{}{}Bye from Zellij!",
|
||||
"{}\n{}{}{}Bye from Zellij!\n",
|
||||
goto_start_of_last_line, restore_snapshot, reset_style, show_cursor
|
||||
);
|
||||
|
||||
|
21
src/main.rs
21
src/main.rs
@ -11,9 +11,10 @@ use common::{
|
||||
command_is_executing, errors, os_input_output, pty_bus, screen, start, utils, wasm_vm,
|
||||
ApiCommand,
|
||||
};
|
||||
use directories_next::ProjectDirs;
|
||||
|
||||
use std::io::Write;
|
||||
use std::os::unix::net::UnixStream;
|
||||
use std::{fs, io::Write};
|
||||
|
||||
use structopt::StructOpt;
|
||||
|
||||
@ -27,6 +28,24 @@ use crate::utils::{
|
||||
};
|
||||
|
||||
pub fn main() {
|
||||
// First run installation of default plugins & layouts
|
||||
let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
|
||||
let data_dir = project_dirs.data_dir();
|
||||
let assets = asset_map! {
|
||||
"plugins/status-bar.wasm",
|
||||
"plugins/strider.wasm",
|
||||
"layouts/default.yaml",
|
||||
"layouts/strider.yaml"
|
||||
};
|
||||
|
||||
for (path, bytes) in assets {
|
||||
let path = data_dir.join(path);
|
||||
fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
if !path.exists() {
|
||||
fs::write(path, bytes).expect("Failed to install default assets!");
|
||||
}
|
||||
}
|
||||
|
||||
let opts = CliArgs::from_args();
|
||||
if let Some(split_dir) = opts.split {
|
||||
match split_dir {
|
||||
|
@ -3,8 +3,8 @@ source: src/tests/integration/layouts.rs
|
||||
expression: last_snapshot
|
||||
|
||||
---
|
||||
Bye from Zellij!█
|
||||
|
||||
Bye from Zellij!
|
||||
█
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user