diff --git a/Cargo.lock b/Cargo.lock index 9b099cf7..22510de6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -716,30 +716,6 @@ dependencies = [ "syn 2.0.117", ] -[[package]] -name = "ctcb-core" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6d666d682b69add1b1bea317cb3184018f21a0ff95f3a9d1b44887bd5b01961" -dependencies = [ - "anyhow", - "serde", - "serde_json", - "thiserror 2.0.18", -] - -[[package]] -name = "ctcb-manifest" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97c47fc9cd2017787aad53c7a11fb8529291cadb369dc15ad041eb81fbc06221" -dependencies = [ - "anyhow", - "ctcb-core", - "serde", - "serde_json", -] - [[package]] name = "ctor" version = "0.2.9" @@ -1059,7 +1035,6 @@ dependencies = [ "axum", "clap", "crossterm", - "ctcb-manifest", "dirs 5.0.1", "flate2", "notify", diff --git a/Cargo.toml b/Cargo.toml index 1be7bf9d..b8d61ff4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,6 @@ flate2 = "1" serde = { version = "1", features = ["derive"] } serde_json = "1" anyhow = "1" -ctcb-manifest = "0.4.1" dirs = "5" strsim = "0.11" crossterm = "0.28" diff --git a/crates/fastled-cli/Cargo.toml b/crates/fastled-cli/Cargo.toml index f3211d5d..17fdf79f 100644 --- a/crates/fastled-cli/Cargo.toml +++ b/crates/fastled-cli/Cargo.toml @@ -34,7 +34,6 @@ tokio = { workspace = true } axum = { workspace = true } tower-http = { workspace = true } tokio-stream = { workspace = true } -ctcb-manifest = { workspace = true } dirs = { workspace = true } tempfile = "3" diff --git a/crates/fastled-cli/src/install.rs b/crates/fastled-cli/src/install.rs index 92048b78..4c55764b 100644 --- a/crates/fastled-cli/src/install.rs +++ b/crates/fastled-cli/src/install.rs @@ -10,10 +10,92 @@ use std::io::{BufReader, BufWriter, Write}; use std::path::{Path, PathBuf}; use anyhow::{bail, Context, Result}; -use ctcb_manifest::{PartRef, PlatformManifest}; +use serde::Deserialize; +use std::collections::BTreeMap; use crate::archive; +// --------------------------------------------------------------------------- +// Manifest schema +// --------------------------------------------------------------------------- +// +// The clang-tool-chain-bins emscripten manifest is served in two different +// shapes depending on platform. Linux/macOS nests version entries under a +// `versions` key: +// +// { "latest": "4.0.21", +// "versions": { "4.0.21": { "href": "...", "sha256": "...", "parts": [...] }, ... } } +// +// Windows inlines version entries at the top level alongside `latest`: +// +// { "latest": "4.0.19", +// "4.0.19": { "href": "...", "sha256": "...", "parts": [...] } } +// +// Our `PlatformManifest` accepts both via a custom Deserialize. + +#[derive(Debug, Deserialize)] +struct PartRef { + href: String, + sha256: String, +} + +#[derive(Debug, Deserialize)] +struct VersionInfo { + href: String, + sha256: String, + parts: Option>, +} + +#[derive(Debug)] +struct PlatformManifest { + latest: String, + versions: BTreeMap, +} + +impl<'de> Deserialize<'de> for PlatformManifest { + fn deserialize>(deserializer: D) -> Result { + let raw: serde_json::Value = Deserialize::deserialize(deserializer)?; + let obj = raw + .as_object() + .ok_or_else(|| serde::de::Error::custom("expected JSON object at manifest root"))?; + + let latest = obj + .get("latest") + .and_then(|v| v.as_str()) + .ok_or_else(|| serde::de::Error::custom("missing 'latest' key"))? + .to_string(); + + let mut versions = BTreeMap::new(); + + // Prefer the nested-`versions` shape (Linux / macOS manifests) when + // present. Fall back to top-level inline entries (Windows). + if let Some(serde_json::Value::Object(versions_obj)) = obj.get("versions") { + for (key, value) in versions_obj { + let info: VersionInfo = serde_json::from_value(value.clone()).map_err(|e| { + serde::de::Error::custom(format!( + "bad version entry '{key}' (nested versions): {e}" + )) + })?; + versions.insert(key.clone(), info); + } + } else { + for (key, value) in obj { + if key == "latest" { + continue; + } + let info: VersionInfo = serde_json::from_value(value.clone()).map_err(|e| { + serde::de::Error::custom(format!( + "bad version entry '{key}' (inline versions): {e}" + )) + })?; + versions.insert(key.clone(), info); + } + } + + Ok(PlatformManifest { latest, versions }) + } +} + const EMSCRIPTEN_MANIFEST_BASE_URL: &str = "https://raw.githubusercontent.com/zackees/clang-tool-chain-bins/main/assets/emscripten"; @@ -172,6 +254,21 @@ pub fn ensure_emscripten_installed() -> Result { fs::create_dir_all(&staging)?; archive::extract_tar_zst(&archive_path, &staging)?; + // Restore execute bits on Unix — some tar implementations (and the + // umask of the extracting process) strip the +x bit from binaries + // under bin/, emscripten/, and libexec/. emcc.py then hits + // PermissionError when it tries to exec clang. Mirror the + // belt-and-suspenders chmod from the previous Python implementation. + #[cfg(unix)] + { + for subdir in ["bin", "emscripten", "libexec"] { + let dir = staging.join(subdir); + if dir.is_dir() { + add_executable_bits_recursive(&dir)?; + } + } + } + fs::write(staging.join("done.txt"), "ok\n")?; if install_dir.exists() { @@ -184,6 +281,29 @@ pub fn ensure_emscripten_installed() -> Result { Ok(install_dir) } +/// Recursively chmod every file under `dir` to include +x for user / group / +/// other (no-op on Windows). Used right after emscripten extraction so the +/// shipped binaries (clang, wasm-ld, etc.) are actually executable. +#[cfg(unix)] +fn add_executable_bits_recursive(dir: &Path) -> Result<()> { + use std::os::unix::fs::PermissionsExt; + for entry in fs::read_dir(dir).with_context(|| format!("read_dir {}", dir.display()))? { + let entry = entry?; + let path = entry.path(); + let file_type = entry.file_type()?; + if file_type.is_dir() { + add_executable_bits_recursive(&path)?; + } else if file_type.is_file() { + let mode = entry.metadata()?.permissions().mode(); + let new_mode = mode | 0o111; + if new_mode != mode { + fs::set_permissions(&path, fs::Permissions::from_mode(new_mode))?; + } + } + } + Ok(()) +} + // --------------------------------------------------------------------------- // esbuild // --------------------------------------------------------------------------- diff --git a/crates/fastled-cli/src/lib.rs b/crates/fastled-cli/src/lib.rs index 5995a334..ba039bdc 100644 --- a/crates/fastled-cli/src/lib.rs +++ b/crates/fastled-cli/src/lib.rs @@ -171,6 +171,20 @@ fn compile_and_serve(dir: &str, cli: &Cli, mode: ViewerMode) -> ExitCode { match install::ensure_emscripten_installed() { Ok(install_dir) => { std::env::set_var("FASTLED_EMSCRIPTEN_DIR", &install_dir); + // FastLED's meson cross-file calls `clang-tool-chain-emcc` / + // `-em++` / `-emar`. Those wrappers (from the `clang-tool-chain` + // PyPI package) look up emscripten under + // `$CLANG_TOOL_CHAIN_DOWNLOAD_PATH/emscripten///`. + // install_dir here is `/emscripten///`, + // so walk four parents up to the toolchains root and export it. + if let Some(root) = install_dir + .parent() + .and_then(|p| p.parent()) + .and_then(|p| p.parent()) + .and_then(|p| p.parent()) + { + std::env::set_var("CLANG_TOOL_CHAIN_DOWNLOAD_PATH", root); + } } Err(e) => { eprintln!("fastled: emscripten toolchain install failed: {e:#}"); @@ -683,6 +697,33 @@ pub fn run() -> ExitCode { } } + // If we're about to delegate a compile to Python (`--just-compile `) + // ensure the emscripten + esbuild toolchains are installed first and + // export the paths through env vars — matches what compile_and_serve() + // does for the non-just-compile path. Without this, Python's emscripten + // toolchain lookup falls through to "not found" on a fresh CI runner. + let needs_compile_toolchain = cli.directory.is_some() && cli.init.is_none() && !cli.install; + if needs_compile_toolchain { + match install::ensure_emscripten_installed() { + Ok(install_dir) => { + std::env::set_var("FASTLED_EMSCRIPTEN_DIR", &install_dir); + } + Err(e) => { + eprintln!("fastled: emscripten toolchain install failed: {e:#}"); + return ExitCode::FAILURE; + } + } + match install::ensure_esbuild_installed() { + Ok(esbuild_path) => { + std::env::set_var("FASTLED_ESBUILD_PATH", &esbuild_path); + } + Err(e) => { + eprintln!("fastled: esbuild install failed: {e:#}"); + return ExitCode::FAILURE; + } + } + } + // --- Delegate to Python for everything else ------------------------------ // (--just-compile, --init, --install, etc.) diff --git a/pyproject.toml b/pyproject.toml index 9f90a6d1..d1f07432 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,20 @@ keywords = ["template-python-cmd"] license = { text = "BSD 3-Clause License" } classifiers = ["Programming Language :: Python :: 3"] dependencies = [ + # Build-system dependencies for the FastLED C++ → WASM compile. + # `meson` configures the build; `ninja` is meson's backend. Both ship + # standalone executables when pip-installed, which the toolchain + # invokes via subprocess from `src/fastled/toolchain/internal_wasm_build.py`. + "meson>=1.4", + "ninja>=1.11", + # FastLED's meson cross-file at `ci/meson/wasm_cross_file.ini` invokes + # `clang-tool-chain-emcc` / `clang-tool-chain-em++` / `clang-tool-chain-emar` + # as the wasm compiler/linker/archiver. Those wrapper scripts are shipped + # by the `clang-tool-chain` PyPI package. The Rust CLI installs the + # underlying emscripten toolchain itself (see install.rs); the wrappers + # find it via the CLANG_TOOL_CHAIN_DOWNLOAD_PATH env var that the Rust + # binary exports before delegating to Python. + "clang-tool-chain>=1.2.6", "zcmds_win32; sys_platform == 'win32'", ]