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
35 changes: 35 additions & 0 deletions .github/workflows/_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,41 @@ jobs:
if: inputs.maturin-target != ''
run: rustup target add "${{ inputs.maturin-target }}"

- name: Build fastled CLI binary (for wheel bundling)
run: |
# Compile the Rust `fastled` CLI and stage it under wheel-data/scripts/
# so maturin packages it into <pkg>-<ver>.data/scripts/ in the wheel.
# See `build-wheel` and `[tool.maturin] data` in pyproject.toml.
if [ -n "${{ inputs.maturin-target }}" ]; then
./_cargo build --release --bin fastled --target "${{ inputs.maturin-target }}"
case "${{ inputs.maturin-target }}" in
*windows*) EXE_NAME="fastled.exe" ;;
*) EXE_NAME="fastled" ;;
esac
BIN_SRC="target/${{ inputs.maturin-target }}/release/${EXE_NAME}"
else
./_cargo build --release --bin fastled
case "$(uname -s)" in
MINGW*|MSYS*|CYGWIN*) EXE_NAME="fastled.exe" ;;
*) EXE_NAME="fastled" ;;
esac
# _cargo forces an MSVC target on Windows even without --target.
if [ -n "${CARGO_BUILD_TARGET:-}" ] || [ "$EXE_NAME" = "fastled.exe" ]; then
ARCH="$(uname -m)"
if [ "$ARCH" = "x86_64" ]; then TRIPLE="x86_64-pc-windows-msvc"; else TRIPLE="aarch64-pc-windows-msvc"; fi
if [ -f "target/${TRIPLE}/release/${EXE_NAME}" ]; then
BIN_SRC="target/${TRIPLE}/release/${EXE_NAME}"
else
BIN_SRC="target/release/${EXE_NAME}"
fi
else
BIN_SRC="target/release/${EXE_NAME}"
fi
fi
mkdir -p wheel-data/scripts
cp -f "$BIN_SRC" "wheel-data/scripts/${EXE_NAME}"
ls -lh wheel-data/scripts/

- name: Build wheel
run: |
if [ -n "${{ inputs.maturin-target }}" ]; then
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,8 @@ vscode-plugin
/target/
/.cargo/
/.rustup/

# Maturin wheel data dir — populated by `./build-wheel` with the Rust
# fastled binary before `maturin build`. Bundled into the wheel as
# <pkg>-<ver>.data/scripts/.
/wheel-data/
56 changes: 56 additions & 0 deletions build-wheel
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
# Build a fastled wheel that bundles the Rust CLI binary as a wheel script.
#
# Maturin's pyo3-binding mode produces the `_native` extension module but
# doesn't ship Rust [[bin]] targets in the wheel. We work around that by
# compiling the binary first, dropping it into `wheel-data/scripts/`, and
# letting maturin package that directory as the wheel's `.data/` tree (see
# `[tool.maturin] data` in pyproject.toml). Pip extracts `data/scripts/*`
# to the venv's Scripts/ (Windows) or bin/ (Unix) on install.

set -euo pipefail

SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"

# Platform-specific binary name and target directory.
case "$(uname -s)" in
MINGW*|MSYS*|CYGWIN*) EXE_NAME="fastled.exe" ;;
*) EXE_NAME="fastled" ;;
esac

echo "Compiling fastled CLI (release)..."
"$SCRIPT_DIR/_cargo" build --release --bin fastled

# Resolve where cargo wrote the binary. The _cargo wrapper sets
# CARGO_BUILD_TARGET on Windows so the binary lands under a triple subdir.
if [[ -n "${CARGO_BUILD_TARGET:-}" ]]; then
BIN_SRC="$SCRIPT_DIR/target/${CARGO_BUILD_TARGET}/release/${EXE_NAME}"
else
BIN_SRC="$SCRIPT_DIR/target/release/${EXE_NAME}"
fi

# Discover from _cargo's exported target on Windows even if not set in env.
case "$(uname -s)" in
MINGW*|MSYS*|CYGWIN*)
ARCH="$(uname -m)"
if [[ "$ARCH" = "x86_64" ]]; then
TARGET_TRIPLE="x86_64-pc-windows-msvc"
else
TARGET_TRIPLE="aarch64-pc-windows-msvc"
fi
BIN_SRC="$SCRIPT_DIR/target/${TARGET_TRIPLE}/release/${EXE_NAME}"
;;
esac

if [[ ! -f "$BIN_SRC" ]]; then
echo "Error: built binary not found at $BIN_SRC" >&2
exit 1
fi

WHEEL_DATA_DIR="$SCRIPT_DIR/wheel-data/scripts"
mkdir -p "$WHEEL_DATA_DIR"
cp -f "$BIN_SRC" "$WHEEL_DATA_DIR/$EXE_NAME"
echo "Staged $BIN_SRC -> $WHEEL_DATA_DIR/$EXE_NAME"

echo "Building wheel..."
uv run maturin build --release "$@"
4 changes: 4 additions & 0 deletions crates/fastled-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ repository.workspace = true
homepage.workspace = true
description = "FastLED WASM compilation CLI"

[lib]
name = "fastled_cli"
path = "src/lib.rs"

[[bin]]
name = "fastled"
path = "src/main.rs"
Expand Down
Loading
Loading