1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# Global Settings
[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
SKIP_TEST = false
# Patching the default flows to skip testing of wasm32-wasi targets
[tasks.pre-test]
condition = { env = { "CARGO_MAKE_CRATE_TARGET_TRIPLE" = "wasm32-wasi" } }
env = { "SKIP_TEST" = true }
[tasks.test]
condition = { env_false = ["SKIP_TEST"] }
dependencies = ["pre-test"]
[tasks.post-test]
env = { "SKIP_TEST" = false }
# Running Zellij using patched layouts
[tasks.run]
workspace = false
dependencies = ["build-workspace", "patch-layouts"]
run_task = "launch"
[tasks.build-workspace]
run_task = { name = "build", fork = true }
[tasks.patch-layouts]
script_runner = "@rust"
script = '''
//! ```cargo
//! [dependencies]
//! yaml-rust = "0.4"
//! ```
use std::{env, error::Error, fs, path::Path};
use yaml_rust::{Yaml, YamlEmitter, YamlLoader};
fn main() -> Result<(), Box<dyn Error>> {
let root = env::var("CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY")?;
let layout_path = Path::new(&root).join("assets/layouts");
for layout in fs::read_dir(layout_path)? {
let layout = layout?.path();
let yaml = fs::read_to_string(&layout)?;
let yaml = YamlLoader::load_from_str(&yaml)?.remove(0);
let yaml = patch_plugins(&root, yaml);
let new_layout = Path::new(&root)
.join("target")
.join(layout.file_name().unwrap());
let mut new_yaml = String::new();
let mut emitter = YamlEmitter::new(&mut new_yaml);
emitter.dump(&yaml)?;
fs::write(new_layout, new_yaml)?;
}
Ok(())
}
fn patch_plugins(root: &str, part: Yaml) -> Yaml {
let mut map = part.into_hash().unwrap();
if let Some(plugin) = map.get_mut(&Yaml::from_str("plugin")) {
let new_plugin = Path::new(root)
.join("target/wasm32-wasi/debug")
.join(plugin.as_str().unwrap());
*plugin = Yaml::String(new_plugin.to_string_lossy().into_owned());
}
if let Some(parts) = map.get_mut(&Yaml::from_str("parts")) {
let new_parts = parts
.clone()
.into_iter()
.map(|p| patch_plugins(root, p))
.collect();
*parts = Yaml::Array(new_parts);
}
Yaml::Hash(map)
}
'''
[tasks.pre-launch]
script_runner = "@duckscript"
script = '''
if is_empty ${CARGO_MAKE_TASK_ARGS}
set_env CARGO_MAKE_TASK_ARGS default
end
'''
[tasks.launch]
dependencies = ["pre-launch"]
command = "cargo"
args = ["run", "--", "-l", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/${CARGO_MAKE_TASK_ARGS}.yaml"]
# Simple clippy tweak
[tasks.clippy]
args = ["clippy", "--", "@@split(CARGO_MAKE_TASK_ARGS,;)"]
# Release building and installing Zellij
[tasks.install]
workspace = false
dependencies = ["build-tiles-release", "wasm-opt-tiles", "build-release", "clear-data-directory"]
script_runner = "@duckscript"
script = '''
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/release/${CARGO_MAKE_CRATE_NAME} ${CARGO_MAKE_TASK_ARGS}
'''
[tasks.build-tiles-release]
env = { "CARGO_MAKE_WORKSPACE_SKIP_MEMBERS" = ["."] }
run_task = { name = "build-release", fork = true }
[tasks.wasm-opt-tiles]
script_runner = "@duckscript"
script = '''
tiles = glob_array ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/wasm32-wasi/release/*.wasm
for tile in ${tiles}
tile_name = basename ${tile}
tile_out = set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/assets/plugins/${tile_name}
if is_path_newer ${tile} ${tile_out}
exec wasm-opt -O ${tile} -o ${tile_out}
end
end
'''
# FIXME: Maybe this should be more generic? Or just blow away the whole directory?
[tasks.clear-data-directory]
script_runner = "@rust"
script = '''
//! ```cargo
//! [dependencies]
//! directories-next = "2.0"
//! ```
use directories_next::ProjectDirs;
use std::fs;
fn main() {
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/tab-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")));
}
'''
# Publishing Zellij
[tasks.publish]
clear = true
workspace = false
dependencies = ["build-tiles-release", "wasm-opt-tiles", "build-release", "publish-zellij-tile", "publish-zellij"]
[tasks.publish-zellij-tile]
cwd = "zellij-tile"
command = "cargo"
args = ["publish"]
[tasks.publish-zellij]
command = "cargo"
args = ["publish"]
|