POSIX conditional compilation:

* All features related to POSIX environments (env vars, shell stuff) gated by feature flags
* Dependencies optional per feature flags
* new CI target for non-POSIX build
* new CI target for release binary artifact

Signed-off-by: Ava Hahn [ava@sunnypup.io](mailto:ava@sunnypup.io)
This commit is contained in:
Ava Apples Affine 2023-05-26 06:41:18 +00:00
parent 5e15109b0c
commit 906cb16355
13 changed files with 330 additions and 319 deletions

View file

@ -28,7 +28,6 @@ use {
CONSOLE_XDIM_VNAME, CONSOLE_YDIM_VNAME, CFG_FILE_VNAME,
L_PROMPT_VNAME, R_PROMPT_VNAME, PROMPT_DELIM_VNAME,
},
aux::{ShellState, check_jobs},
},
std::{
cell::RefCell,
@ -46,12 +45,17 @@ use {
ColumnarMenu, Emacs, ReedlineMenu,
default_emacs_keybindings,
},
nix::unistd,
nu_ansi_term::{Color, Style},
dirs::home_dir,
termion::terminal_size,
};
#[cfg(feature="posix")]
use relish::aux::{ShellState, check_jobs};
#[cfg(feature="posix")]
use nix::unistd;
#[derive(Clone)]
pub struct CustomPrompt(String, String, String);
#[derive(Clone)]
@ -237,24 +241,16 @@ fn main() {
let hist_file_name = home_dir.clone() + HIST_FILE;
let cfg_file_name = home_dir + CONFIG_FILE_DEFAULT;
// TODO: the next two decls should probably be conditional on CFG_RELISH_POSIX
// but in both cases the data must live for the whole program
let shell_state_bindings = Rc::new(RefCell::from(ShellState {
parent_pid: unistd::Pid::from_raw(0),
parent_sid: unistd::Pid::from_raw(0),
children: vec![],
last_exit_code: 0,
attr: None,
}));
let prompt_ss = shell_state_bindings.clone();
// setup symtable
let mut syms = SymTable::new();
load_defaults(&mut syms);
load_environment(&mut syms);
static_stdlib(&mut syms).unwrap_or_else(|err: String| eprintln!("{}", err));
static_stdlib(&mut syms);
// reload this later with the state bindings
dynamic_stdlib(&mut syms, None).unwrap_or_else(|err: String| eprintln!("{}", err));
#[cfg(feature="posix")]
dynamic_stdlib(&mut syms, None);
#[cfg(not(feature="posix"))]
dynamic_stdlib(&mut syms);
// if there are args those are scripts, run them and exit
if env::args().count() > 1 {
@ -274,10 +270,23 @@ fn main() {
run(cfg_file.clone(), &mut syms)
.unwrap_or_else(|err: Traceback| eprintln!("failed to load script {}\n{}", cfg_file, err));
}
dynamic_stdlib(&mut syms, Some(shell_state_bindings)).unwrap_or_else(|err: String| eprintln!("{}", err));
#[cfg(feature="posix")]
let prompt_ss: Rc<RefCell<ShellState>>;
#[cfg(feature="posix")]
{
let shell_state_bindings = Rc::new(RefCell::from(ShellState {
parent_pid: unistd::Pid::from_raw(0),
parent_sid: unistd::Pid::from_raw(0),
children: vec![],
last_exit_code: 0,
attr: None,
}));
prompt_ss = shell_state_bindings.clone();
dynamic_stdlib(&mut syms, Some(shell_state_bindings));
}
// setup readline
let completion_menu = Box::new(ColumnarMenu::default().with_name("completion_menu"));
let mut keybindings = default_emacs_keybindings();
add_menu_keybindings(&mut keybindings);
@ -305,8 +314,8 @@ fn main() {
let mut xdimension: u16 = 0;
let mut ydimension: u16 = 0;
loop {
#[cfg(feature="posix")]
{
// update state
check_jobs(&mut prompt_ss.borrow_mut());
}
let readline_prompt = make_prompt(&mut syms);

View file

@ -51,7 +51,10 @@ pub mod stdlib {
}
pub mod aux {
#[cfg(feature="posix")]
pub use crate::stl::posix::args_from_ast;
#[cfg(feature="posix")]
pub use crate::stl::posix::ShellState;
#[cfg(feature="posix")]
pub use crate::stl::posix::check_jobs;
}

View file

@ -23,7 +23,9 @@ use std::rc::Rc;
use std::cell::RefCell;
use std::env::vars;
#[cfg(feature = "posix")]
pub mod posix;
pub mod append;
pub mod boolean;
pub mod control;
@ -57,7 +59,7 @@ fn prompt_delimiter_default_callback(_: &Seg, _: &mut SymTable) -> Result<Ctr, T
/// static_stdlib
/// inserts all stdlib functions that can be inserted without
/// any kind of further configuration data into a symtable
pub fn static_stdlib(syms: &mut SymTable) -> Result<(), String> {
pub fn static_stdlib(syms: &mut SymTable) {
append::add_list_lib(syms);
strings::add_string_lib(syms);
decl::add_decl_lib_static(syms);
@ -76,24 +78,21 @@ pub fn static_stdlib(syms: &mut SymTable) -> Result<(), String> {
..Default::default()
}
);
Ok(())
}
/// dynamic_stdlib
/// takes configuration data and uses it to insert dynamic
/// callbacks with configuration into a symtable
pub fn dynamic_stdlib(syms: &mut SymTable, shell: Option<Rc<RefCell<posix::ShellState>>>) -> Result<(), String> {
//get CFG_RELISH_ENV from syms
#[cfg(feature="posix")]
pub fn dynamic_stdlib(syms: &mut SymTable, shell: Option<Rc<RefCell<posix::ShellState>>>) {
// get CFG_RELISH_ENV from syms
let env_cfg_user_form = syms
.call_symbol(&MODENV_CFG_VNAME.to_string(), &Seg::new(), true)
.unwrap_or_else(|_: Traceback| Box::new(Ctr::None))
.to_string()
.eq("true");
decl::add_decl_lib_dynamic(syms, env_cfg_user_form);
// This should be replaced by actual compiler conditionals in the future
if let Some(shell_state) = shell {
let posix_cfg_user_form = syms
.call_symbol(&POSIX_CFG_VNAME.to_string(), &Seg::new(), true)
@ -105,8 +104,11 @@ pub fn dynamic_stdlib(syms: &mut SymTable, shell: Option<Rc<RefCell<posix::Shell
posix::load_posix_shell(syms, shell_state);
}
}
}
Ok(())
#[cfg(not(feature="posix"))]
pub fn dynamic_stdlib(syms: &mut SymTable) {
decl::add_decl_lib_dynamic(syms, false);
}
pub fn load_environment(syms: &mut SymTable) {