zellij/zellij-utils/src/consts.rs
har7an d1f50150f6
WIP: Use xtask as build system (#2012)
* xtask: Implement a new build system

xtask is a cargo alias that is used to extend the cargo build system
with custom commands. For an introduction to xtask, see here:
https://github.com/matklad/cargo-xtask/

The idea is that instead of writing makefiles, xtask requires no
additional dependencies except `cargo` and `rustc`, which must be
available to build the project anyway.

This commit provides a basic implementation of the `build` and `test`
subcommands.

* xtask/deps: Add 'which'

* xtask/test: Handle error when cargo not found

* xtask/flags: Add more commands

to perform different useful tasks. Includes:

- clippy
- format
- "make" (composite)
- "install" (composite)

Also add more options to `build` to selectively compile plugins or leave
them out entirely.

* xtask/main: Return error when cargo not found

* xtask/build: Add more subtasks

- `wasm_opt_plugins` and
- `manpage`

that perform other build commands. Add thorough documentation on what
each of these does and also handle the new `build` cli flags
appropriately.

* xtask/clippy: Add job to run clippy

* xtask/format: Add job to run rustfmt

* xtask/pipeline: Add composite commands

that perform multiple atomic xtask commands sequentially in a pipeline
sort of fashion.

* xtask/deps: Pin dependencies

* xtask/main: Integrate new jobs

and add documentation.

* xtask: Implement 'dist'

which performs an 'install' and copies the resulting zellij binary along
with some other assets to a `target/dist` folder.

* cargo: Update xflags version

* xtask: Measure task time, update tty title

* xtask: Update various tasks

* xtask: wasm-opt plugins in release builds

automatically.

* xtask/build: Copy debug plugins to assets folder

* xtask: Add 'run' subcommand

* xtask: Add arbitrary args to test and run

* xtask: Rearrange CLI commands in help

* xtask: Add deprecation notice

* docs: Replace `cargo make` with `xtask`

* github: Use `xtask` in workflows.

* xtask: Add support for CI commands

* xtask: Streamline error handling

* github: Use new xtask commands in CI

* xtask: Add 'publish' job

* xtask/publish: Add retry when publish fails

* xtask: Apply rustfmt

* xtask: Refine 'make' deprecation warning

* xtask: add task to build manpage

* contributing: Fix e2e commands

* xtask/run: Add missing `--`

to pass all arguments following `xtask run` directly to the zellij
binary being run.

* xtask: Stay in invocation dir

and make all tasks that need it change to the project root dir
themselves.

* xtask/run: Add `--data-dir` flag

which will allow very quick iterations when not changing the plugins
between builds.

* xtask/ci: Install dependencies without asking

* utils: Allow including plugins from target folder

* utils/assets: Reduce asset map complexity

* utils/consts: Update asset map docs

* xtask: Fix plugin includes

* xtask/test: Build plugins first

because the zellij binary needs to include the plugins.

* xtask/test: Fix formatting

* xtask: Add notice on how to disable it
2022-12-17 13:27:18 +00:00

127 lines
4.3 KiB
Rust

//! Zellij program-wide constants.
use directories_next::ProjectDirs;
use lazy_static::lazy_static;
use once_cell::sync::OnceCell;
use std::path::PathBuf;
pub const ZELLIJ_CONFIG_FILE_ENV: &str = "ZELLIJ_CONFIG_FILE";
pub const ZELLIJ_CONFIG_DIR_ENV: &str = "ZELLIJ_CONFIG_DIR";
pub const ZELLIJ_LAYOUT_DIR_ENV: &str = "ZELLIJ_LAYOUT_DIR";
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const DEFAULT_SCROLL_BUFFER_SIZE: usize = 10_000;
pub static SCROLL_BUFFER_SIZE: OnceCell<usize> = OnceCell::new();
pub static DEBUG_MODE: OnceCell<bool> = OnceCell::new();
pub const SYSTEM_DEFAULT_CONFIG_DIR: &str = "/etc/zellij";
pub const SYSTEM_DEFAULT_DATA_DIR_PREFIX: &str = system_default_data_dir();
const fn system_default_data_dir() -> &'static str {
if let Some(data_dir) = std::option_env!("PREFIX") {
data_dir
} else {
"/usr"
}
}
lazy_static! {
pub static ref ZELLIJ_PROJ_DIR: ProjectDirs =
ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
pub static ref ZELLIJ_CACHE_DIR: PathBuf = ZELLIJ_PROJ_DIR.cache_dir().to_path_buf();
}
pub const FEATURES: &[&str] = &[
#[cfg(feature = "disable_automatic_asset_installation")]
"disable_automatic_asset_installation",
];
#[cfg(not(target_family = "wasm"))]
pub use not_wasm::*;
#[cfg(not(target_family = "wasm"))]
mod not_wasm {
use lazy_static::lazy_static;
use std::collections::HashMap;
use std::path::PathBuf;
// Convenience macro to add plugins to the asset map (see `ASSET_MAP`)
//
// Plugins are taken from:
//
// - `zellij-utils/assets/plugins`: When building in release mode OR when the
// `plugins_from_target` feature IS NOT set
// - `zellij-utils/../target/wasm32-wasi/debug`: When building in debug mode AND the
// `plugins_from_target` feature IS set
macro_rules! add_plugin {
($assets:expr, $plugin:literal) => {
$assets.insert(
PathBuf::from("plugins").join($plugin),
#[cfg(any(not(feature = "plugins_from_target"), not(debug_assertions)))]
include_bytes!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/plugins/",
$plugin
))
.to_vec(),
#[cfg(all(feature = "plugins_from_target", debug_assertions))]
include_bytes!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../target/wasm32-wasi/debug/",
$plugin
))
.to_vec(),
);
};
}
lazy_static! {
// Zellij asset map
pub static ref ASSET_MAP: HashMap<PathBuf, Vec<u8>> = {
let mut assets = std::collections::HashMap::new();
add_plugin!(assets, "compact-bar.wasm");
add_plugin!(assets, "status-bar.wasm");
add_plugin!(assets, "tab-bar.wasm");
add_plugin!(assets, "strider.wasm");
assets
};
}
}
#[cfg(unix)]
pub use unix_only::*;
#[cfg(unix)]
mod unix_only {
use super::*;
use crate::envs;
use crate::shared::set_permissions;
use lazy_static::lazy_static;
use nix::unistd::Uid;
use std::{env::temp_dir, fs};
lazy_static! {
static ref UID: Uid = Uid::current();
pub static ref ZELLIJ_IPC_PIPE: PathBuf = {
let mut sock_dir = ZELLIJ_SOCK_DIR.clone();
fs::create_dir_all(&sock_dir).unwrap();
set_permissions(&sock_dir, 0o700).unwrap();
sock_dir.push(envs::get_session_name().unwrap());
sock_dir
};
pub static ref ZELLIJ_TMP_DIR: PathBuf = temp_dir().join(format!("zellij-{}", *UID));
pub static ref ZELLIJ_TMP_LOG_DIR: PathBuf = ZELLIJ_TMP_DIR.join("zellij-log");
pub static ref ZELLIJ_TMP_LOG_FILE: PathBuf = ZELLIJ_TMP_LOG_DIR.join("zellij.log");
pub static ref ZELLIJ_SOCK_DIR: PathBuf = {
let mut ipc_dir = envs::get_socket_dir().map_or_else(
|_| {
ZELLIJ_PROJ_DIR
.runtime_dir()
.map_or_else(|| ZELLIJ_TMP_DIR.clone(), |p| p.to_owned())
},
PathBuf::from,
);
ipc_dir.push(VERSION);
ipc_dir
};
}
}