Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/bashkit-python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ num-bigint = "^0.4.6"
# http_client/sqlite/interop pull mio/tokio-net/rt-multi-thread/tokio::fs,
# none of which compile on wasm32-unknown-emscripten — see the wasm block
# below and knowledge/runtimes/emscripten-wheels.md.
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
[target.'cfg(not(target_family = "wasm"))'.dependencies]
bashkit = { path = "../bashkit", features = ["python", "typescript", "realfs", "jq", "interop", "http_client", "sqlite", "terminal"] }
bashkit-scripted-tool = { path = "../bashkit-scripted-tool", features = ["python", "jq"] }
tokio = { workspace = true, features = ["rt-multi-thread"] }
Expand All @@ -49,7 +49,7 @@ pyo3-async-runtimes = { workspace = true }
# shell plus the embedded jq and Monty Python interpreters. tokio stays on its
# wasm-safe base features (sync, macros, io-util, rt, time) — current-thread
# runtime only. See knowledge/runtimes/emscripten-wheels.md.
[target.'cfg(target_arch = "wasm32")'.dependencies]
[target.'cfg(target_family = "wasm")'.dependencies]
bashkit = { path = "../bashkit", features = ["python", "typescript", "jq", "terminal"] }
bashkit-scripted-tool = { path = "../bashkit-scripted-tool", features = ["python", "jq"] }
tokio = { workspace = true }
144 changes: 72 additions & 72 deletions crates/bashkit-python/src/lib.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions crates/bashkit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ name = "markkit_fetchkit"
required-features = ["markkit", "fetchkit"]

# Additional tokio features needed only on native (not WASM)
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
[target.'cfg(not(target_family = "wasm"))'.dependencies]
tokio = { version = "1", features = ["rt-multi-thread", "fs"] }
# Grows the native stack on demand while polling nested interpreter
# futures, so deep (but limit-bounded) nesting cannot abort the process
Expand All @@ -460,10 +460,10 @@ fetchkit = { version = "0.7.2", default-features = false, features = ["docs-pdf"
# pulled in by `wasm_js`. A non-JS wasm embedder gets time_compat::host_clock
# instead and links none of them: their imports would be unresolvable in a
# runtime with no JS engine.
[target.'cfg(target_arch = "wasm32")'.dependencies]
[target.'cfg(target_family = "wasm")'.dependencies]
web-time = { workspace = true, optional = true }

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
gloo-timers = { version = "0.4", features = ["futures"], optional = true }
send_wrapper = { version = "0.6", features = ["futures"], optional = true }
# Task spawner for the host-call execution driver (see host_call.rs). JS-backed
Expand All @@ -482,6 +482,6 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(feature, values("i18n-deci

# The process feature is native test infrastructure only; keep WASM builds
# on the workspace Tokio feature set without changing versions or the lock.
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
[target.'cfg(not(target_family = "wasm"))'.dev-dependencies]
tokio = { workspace = true, features = ["process"] }

8 changes: 4 additions & 4 deletions crates/bashkit/src/builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mod export;
mod expr;
mod factor;
mod fc;
#[cfg(all(feature = "fetchkit", not(target_arch = "wasm32")))]
#[cfg(all(feature = "fetchkit", not(target_family = "wasm")))]
mod fetchkit;
mod fileops;
mod find;
Expand Down Expand Up @@ -88,7 +88,7 @@ mod ls;
mod make;
mod man;
mod mapfile;
#[cfg(all(feature = "markkit", not(target_arch = "wasm32")))]
#[cfg(all(feature = "markkit", not(target_family = "wasm")))]
mod markkit;
mod mkfifo;
#[cfg(feature = "terminal")]
Expand Down Expand Up @@ -202,7 +202,7 @@ pub use export::Export;
pub use expr::Expr;
pub use factor::Factor;
pub use fc::Fc;
#[cfg(all(feature = "fetchkit", not(target_arch = "wasm32")))]
#[cfg(all(feature = "fetchkit", not(target_family = "wasm")))]
pub use fetchkit::Fetchkit;
pub use fileops::{Chmod, Chown, Cp, Ln, Mkdir, Mktemp, Mv, Rm, Touch};
pub use find::Find;
Expand Down Expand Up @@ -231,7 +231,7 @@ pub(crate) use ls::{fnmatch, glob_match};
pub use make::Make;
pub use man::Man;
pub use mapfile::Mapfile;
#[cfg(all(feature = "markkit", not(target_arch = "wasm32")))]
#[cfg(all(feature = "markkit", not(target_family = "wasm")))]
pub use markkit::Markkit;
pub use mkfifo::Mkfifo;
pub use navigation::{Cd, Pwd};
Expand Down
6 changes: 3 additions & 3 deletions crates/bashkit/src/builtins/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use async_trait::async_trait;
use std::time::Duration;

#[cfg(all(
target_arch = "wasm32",
target_family = "wasm",
target_os = "unknown",
not(feature = "wasm_js")
))]
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Builtin for Sleep {
if seconds > 0.0 {
let duration = Duration::from_secs_f64(seconds);
#[cfg(all(
target_arch = "wasm32",
target_family = "wasm",
target_os = "unknown",
not(feature = "wasm_js")
))]
Expand Down Expand Up @@ -109,7 +109,7 @@ fn parse_interval(arg: &str) -> Option<f64> {
#[cfg(any(
test,
all(
target_arch = "wasm32",
target_family = "wasm",
target_os = "unknown",
not(feature = "wasm_js")
)
Expand Down
32 changes: 16 additions & 16 deletions crates/bashkit/src/builtins/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::future::Future;
use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::sync::Arc;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
use std::sync::OnceLock;
use std::time::Duration;
use zapcode_core::{ResourceLimits, RunResult, Value, VmState, ZapcodeRun};
Expand Down Expand Up @@ -51,13 +51,13 @@ const TS_CALL_WORK_UNITS: u64 = 4096;
/// in debug builds (32 MiB was the smallest that passed
/// `deep_nesting_at_the_limit_does_not_overflow` in a debug build; 128 MiB
/// gives 4x). The memory is reserved, not committed, until used.
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
const TS_VM_STACK_BYTES: usize = 128 * 1024 * 1024;

/// Upper bound used when the host does not configure TypeScript VM admission.
/// Four active 128 MiB stack reservations are a deliberate process-wide cap,
/// while smaller hosts default to their available CPU parallelism.
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
const DEFAULT_MAX_ACTIVE_TS_VMS: usize = 4;

/// Error returned by [`configure_typescript_vm_concurrency`].
Expand Down Expand Up @@ -110,7 +110,7 @@ pub fn configure_typescript_vm_concurrency(
maximum: tokio::sync::Semaphore::MAX_PERMITS,
});
}
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
{
TS_VM_ADMISSION
.set(VmAdmission::new(max_active))
Expand All @@ -121,14 +121,14 @@ pub fn configure_typescript_vm_concurrency(
Ok(())
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
#[derive(Clone)]
struct VmAdmission {
semaphore: Arc<tokio::sync::Semaphore>,
limit: usize,
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
impl VmAdmission {
fn new(limit: usize) -> Self {
Self {
Expand All @@ -155,10 +155,10 @@ impl VmAdmission {
}
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
static TS_VM_ADMISSION: OnceLock<VmAdmission> = OnceLock::new();

#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
fn vm_admission() -> &'static VmAdmission {
TS_VM_ADMISSION.get_or_init(|| {
let parallelism = std::thread::available_parallelism().map_or(1, usize::from);
Expand Down Expand Up @@ -1024,7 +1024,7 @@ async fn run_typescript(

// Per-run heap meter (vm_meter.rs); ZapCode itself never enforces
// max_memory, so without the metered allocator `ts` fails closed.
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
if !crate::vm_meter::allocator_installed() {
return Ok(ExecResult::err(METER_MISSING_ERROR.to_string(), 1));
}
Expand Down Expand Up @@ -1090,11 +1090,11 @@ async fn run_typescript(
const VM_THREAD_ERROR: &str = "ts: cannot start execution thread\n";

/// Message when `MeteredAllocator` is not the global allocator.
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
const METER_MISSING_ERROR: &str =
"ts: TypeScript memory limits need bashkit::MeteredAllocator as the global allocator\n";

#[cfg_attr(target_arch = "wasm32", allow(dead_code))]
#[cfg_attr(target_family = "wasm", allow(dead_code))]
enum VmStepResult<T> {
Complete(T),
TimedOut,
Expand All @@ -1108,7 +1108,7 @@ enum VmStepResult<T> {
/// blocking pool. The permit lives inside that blocking task, so a caller
/// whose deadline expires cannot release the slot while its abandoned VM
/// thread is still winding down.
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
async fn run_vm_step<T: Send + 'static>(
meter: Arc<crate::vm_meter::VmMeter>,
deadline: Option<Instant>,
Expand All @@ -1117,7 +1117,7 @@ async fn run_vm_step<T: Send + 'static>(
run_vm_step_with_admission(vm_admission().clone(), meter, deadline, step).await
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
async fn run_vm_step_with_admission<T: Send + 'static>(
admission: VmAdmission,
meter: Arc<crate::vm_meter::VmMeter>,
Expand Down Expand Up @@ -1161,7 +1161,7 @@ async fn run_vm_step_with_admission<T: Send + 'static>(
/// Run one synchronous ZapCode step (parse/compile/run, or a resume) inside
/// `meter`'s window on a dedicated [`TS_VM_STACK_BYTES`] stack. `None` means
/// no thread could be started.
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
fn on_vm_stack<T: Send + 'static>(
meter: &crate::vm_meter::VmMeter,
step: impl FnOnce() -> T + Send + 'static,
Expand All @@ -1184,7 +1184,7 @@ fn on_vm_stack<T: Send + 'static>(

/// wasm32 has no threads: run on the current stack. The nesting cap still
/// applies; see the zapcode-runtime knowledge page for the residual risk.
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
async fn run_vm_step<T>(
meter: Arc<crate::vm_meter::VmMeter>,
_deadline: Option<Instant>,
Expand Down Expand Up @@ -1919,7 +1919,7 @@ mod tests {
));
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn vm_admission_caps_active_threads_and_times_out_queued_steps() {
use std::sync::atomic::{AtomicUsize, Ordering};
Expand Down
6 changes: 3 additions & 3 deletions crates/bashkit/src/host_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl Drop for ExecutionHandle {
/// Hand the execution to an independent task so its deadline keeps running
/// while the host is parked. Returns the future back when this target has no
/// task spawner, leaving `next_event` as its only driver.
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
fn spawn_execution(future: ExecutionFuture) -> Option<ExecutionFuture> {
// Not every embedder polls `next_event` from inside a Tokio runtime, and
// `start_execution` must not start panicking on the ones that don't.
Expand All @@ -378,7 +378,7 @@ fn spawn_execution(future: ExecutionFuture) -> Option<ExecutionFuture> {
}
}

#[cfg(all(target_arch = "wasm32", target_os = "unknown", feature = "wasm_js"))]
#[cfg(all(target_family = "wasm", target_os = "unknown", feature = "wasm_js"))]
fn spawn_execution(future: ExecutionFuture) -> Option<ExecutionFuture> {
wasm_bindgen_futures::spawn_local(future);
None
Expand All @@ -389,7 +389,7 @@ fn spawn_execution(future: ExecutionFuture) -> Option<ExecutionFuture> {
// still enforced, just on the host's next poll. See
// knowledge/runtimes/non-js-wasm.md.
#[cfg(all(
target_arch = "wasm32",
target_family = "wasm",
target_os = "unknown",
not(feature = "wasm_js")
))]
Expand Down
8 changes: 4 additions & 4 deletions crates/bashkit/src/interpreter/grow_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ use std::task::{Context, Poll};
/// Remaining stack below which a poll moves to a new segment. Must exceed
/// the stack one interpreter level can use between two command polls in a
/// debug build (measured at ~150 KiB for an `eval` level).
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
const RED_ZONE: usize = 512 * 1024;

/// Size of each additional stack segment.
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
const SEGMENT: usize = 4 * 1024 * 1024;

/// Future wrapper whose `poll` runs with at least [`RED_ZONE`] bytes of stack.
Expand All @@ -42,11 +42,11 @@ impl<F: Future> Future for GrowStack<F> {

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let inner = self.0.as_mut();
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
{
stacker::maybe_grow(RED_ZONE, SEGMENT, || inner.poll(cx))
}
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
{
inner.poll(cx)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bashkit/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2345,9 +2345,9 @@ impl Interpreter {
builtins.insert("jq".to_string(), Arc::new(builtins::Jq));
#[cfg(feature = "jq")]
builtins.insert("yq".to_string(), Arc::new(builtins::Yq));
#[cfg(all(feature = "markkit", not(target_arch = "wasm32")))]
#[cfg(all(feature = "markkit", not(target_family = "wasm")))]
builtins.insert("markkit".to_string(), Arc::new(builtins::Markkit));
#[cfg(all(feature = "fetchkit", not(target_arch = "wasm32")))]
#[cfg(all(feature = "fetchkit", not(target_family = "wasm")))]
builtins.insert("fetchkit".to_string(), Arc::new(builtins::Fetchkit));

// Custom-construction builtins that need parameters
Expand Down
2 changes: 1 addition & 1 deletion crates/bashkit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4323,7 +4323,7 @@ pub mod sqlite_guide {}
/// **Related:** `BashBuilder::network`, `NetworkAllowlist`, [`threat_model`]
#[cfg(all(
any(feature = "markkit", feature = "fetchkit"),
not(target_arch = "wasm32")
not(target_family = "wasm")
))]
#[doc = include_str!("../docs/markkit-fetchkit.md")]
pub mod markkit_fetchkit_guide {}
Expand Down
Loading
Loading