Skip to content
Open
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
5 changes: 5 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[target.x86_64-unknown-linux-gnu]
linker = "scripts/zig-cc-x86_64-unknown-linux-gnu.sh"

[target.aarch64-unknown-linux-gnu]
linker = "scripts/zig-cc-aarch64-unknown-linux-gnu.sh"
6 changes: 5 additions & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repository contains:
## Tech Stack

- **Languages**: Rust (2021 edition), TypeScript, JavaScript
- **Build Tools**: Cargo, wasm-pack, Bun (v1.3.3)
- **Build Tools**: Cargo, Zig, cargo-zigbuild, wasm-pack, Bun (v1.3.3)
- **Testing**: Cargo test, wasm-pack test, Bun test
- **Key Dependencies**:
- Rust: clap (v4.5+), crossterm (v0.28+), filedescriptor
Expand Down Expand Up @@ -48,6 +48,10 @@ bun run build:page # Web page
bun run build:websl:rust
```

Release CI cross-compiles the CLI from Linux. Linux GNU targets use the checked-in Zig linker wrappers under `scripts/`
and `.cargo/config.toml`; Windows targets use `cargo-zigbuild` for `x86_64-pc-windows-gnu` and
`aarch64-pc-windows-gnullvm` instead of MSVC-hosted compilation.

### Testing

```bash
Expand Down
136 changes: 129 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,142 @@ concurrency:
cancel-in-progress: true

jobs:
cross-build:
name: Cross Build (${{ matrix.target }})
runs-on: ubuntu-latest
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
arch: x86_64
package: deb
builder: cargo
linker_env: CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER
linker: scripts/zig-cc-x86_64-unknown-linux-gnu.sh
- target: aarch64-unknown-linux-gnu
arch: aarch64
package: deb
builder: cargo
linker_env: CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER
linker: scripts/zig-cc-aarch64-unknown-linux-gnu.sh
- target: x86_64-pc-windows-gnu
arch: x86_64
package: nsis
builder: zigbuild
- target: aarch64-pc-windows-gnullvm
arch: aarch64
package: nsis
builder: zigbuild
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache Cargo Registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ubuntu-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.16.0
- name: Install Rust target
run: rustup target add ${{ matrix.target }}
- name: Configure Zig linker
if: matrix.builder == 'cargo'
run: |
echo "${{ matrix.linker_env }}=${{ matrix.linker }}" >> $GITHUB_ENV
- name: Install cargo-zigbuild
if: matrix.builder == 'zigbuild'
run: cargo install cargo-zigbuild --version 0.23.0 --locked
- name: Build Debug with Cargo
if: matrix.builder == 'cargo'
run: cargo build --manifest-path=apps/sl/Cargo.toml --target=${{ matrix.target }}
- name: Build Release with Cargo
if: matrix.builder == 'cargo'
run: COMPLETION_DIR="$(pwd)/completions" cargo build --manifest-path=apps/sl/Cargo.toml --release --target=${{ matrix.target }}
- name: Build Debug with cargo-zigbuild
if: matrix.builder == 'zigbuild'
run: cargo zigbuild --manifest-path=apps/sl/Cargo.toml --target=${{ matrix.target }}
- name: Build Release with cargo-zigbuild
if: matrix.builder == 'zigbuild'
run: COMPLETION_DIR="$(pwd)/completions" cargo zigbuild --manifest-path=apps/sl/Cargo.toml --release --target=${{ matrix.target }}
- name: Install cargo-deb
if: matrix.package == 'deb'
run: cargo install cargo-deb
- name: Build .deb Package
if: matrix.package == 'deb'
id: deb_build
run: |
cargo deb --manifest-path=apps/sl/Cargo.toml --target=${{ matrix.target }} --no-build
DEB_FILE=$(ls target/${{ matrix.target }}/debian/sl_*.deb)
echo "deb_file=${DEB_FILE}" >> $GITHUB_OUTPUT
echo "deb_name=$(basename "${DEB_FILE}")" >> $GITHUB_OUTPUT
- name: Test .deb Package
if: matrix.package == 'deb'
run: |
dpkg -I ${{ steps.deb_build.outputs.deb_file }}
dpkg -c ${{ steps.deb_build.outputs.deb_file }}
- name: Upload .deb Package
if: matrix.package == 'deb'
uses: actions/upload-artifact@v4
with:
name: ${{ steps.deb_build.outputs.deb_name }}
path: ${{ steps.deb_build.outputs.deb_file }}
- name: Install NSIS
if: matrix.package == 'nsis'
run: |
sudo apt-get update
sudo apt-get install -y nsis
- name: Build Windows installer
if: matrix.package == 'nsis'
id: installer_build
run: |
cmake -S . -B target/installer-${{ matrix.target }} -DSL_TARGET="${{ matrix.target }}" -DARCH="${{ matrix.arch }}"
cpack --config target/installer-${{ matrix.target }}/CPackConfig.cmake -C Release
INSTALLER=$(find target/installer-${{ matrix.target }} -maxdepth 1 -name 'sl-*.exe' -print -quit)
if [ -z "$INSTALLER" ]; then
echo "No installer produced" >&2
exit 1
fi
echo "installer=${INSTALLER}" >> $GITHUB_OUTPUT
echo "installer_name=$(basename "${INSTALLER}")" >> $GITHUB_OUTPUT
- name: Upload Installer
if: matrix.package == 'nsis'
uses: actions/upload-artifact@v4
with:
name: ${{ steps.installer_build.outputs.installer_name }}
path: ${{ steps.installer_build.outputs.installer }}

macos-smoke:
name: macOS Smoke
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache Cargo Registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: macos-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Build Debug
run: cargo build
- name: Build Release
run: cargo build --release
- name: Test CLI
run: |
./target/debug/sl -h
./target/debug/sl -V
./target/release/sl -h
./target/release/sl -V

build-fedora:
uses: ./.github/workflows/fedora-build.yml
build-posix:
uses: ./.github/workflows/posix-build.yml
build-ubuntu:
uses: ./.github/workflows/ubuntu-build.yml
build-windows:
uses: ./.github/workflows/win-build.yml
build-pages:
uses: ./.github/workflows/site.yml

release:
name: Release
needs: [build-fedora, build-posix, build-ubuntu, build-windows]
needs: [cross-build, macos-smoke, build-fedora]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/sl-')
runs-on: ubuntu-latest
permissions:
Expand Down
29 changes: 0 additions & 29 deletions .github/workflows/posix-build.yml

This file was deleted.

54 changes: 0 additions & 54 deletions .github/workflows/ubuntu-build.yml

This file was deleted.

54 changes: 0 additions & 54 deletions .github/workflows/win-build.yml

This file was deleted.

33 changes: 30 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,27 @@ cmake_minimum_required(VERSION 3.28)
project("SL"
VERSION 6.1.5
DESCRIPTION "CHOO CHOO"
LANGUAGES C)
LANGUAGES NONE)

find_program(SL_EXE NAMES sl.exe PATHS "${PROJECT_BINARY_DIR}/release" "${PROJECT_BINARY_DIR}/${ARCH}-pc-windows-msvc/release" REQUIRED)
install(FILES ${CURSES_DLL} ${SL_EXE} DESTINATION bin COMPONENT applications)
set(SL_TARGET "" CACHE STRING "Rust target triple containing the sl.exe release build")
set(ARCH "" CACHE STRING "Release artifact architecture label")

set(SL_EXE_SEARCH_PATHS "${CMAKE_SOURCE_DIR}/target/release")
if(SL_TARGET)
list(APPEND SL_EXE_SEARCH_PATHS "${CMAKE_SOURCE_DIR}/target/${SL_TARGET}/release")
endif()
if(ARCH)
list(APPEND SL_EXE_SEARCH_PATHS "${CMAKE_SOURCE_DIR}/target/${ARCH}-pc-windows-msvc/release")
endif()

find_program(SL_EXE NAMES sl.exe PATHS ${SL_EXE_SEARCH_PATHS} NO_DEFAULT_PATH REQUIRED)

set(SL_INSTALL_FILES "${SL_EXE}")
if(DEFINED CURSES_DLL AND NOT "${CURSES_DLL}" STREQUAL "")
list(APPEND SL_INSTALL_FILES "${CURSES_DLL}")
endif()

install(FILES ${SL_INSTALL_FILES} DESTINATION bin COMPONENT applications)

set(CPACK_PACKAGE_NAME "sl")
set(CPACK_PACKAGE_VENDOR "sl")
Expand All @@ -15,6 +32,16 @@ set(CPACK_PACKAGE_VERSION_MAJOR "6")
set(CPACK_PACKAGE_VERSION_MINOR "1")
set(CPACK_PACKAGE_VERSION_PATCH "5")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "sl")
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}")
set(CPACK_GENERATOR "NSIS")
if(ARCH STREQUAL "aarch64")
set(CPACK_SYSTEM_NAME "woa64")
elseif(ARCH STREQUAL "x86_64")
set(CPACK_SYSTEM_NAME "win64")
endif()
if(CPACK_SYSTEM_NAME)
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}")
endif()
set(CPACK_COMPONENTS_ALL applications)
set(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "sl")
set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION "SL (Steam Locomotive) runs across your terminal")
Expand Down
13 changes: 13 additions & 0 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ bun run setup

`bun run setup` は、Web サイトのビルドに必要な Rust の `wasm32-unknown-unknown` ターゲットと `wasm-pack`
をインストールします。ビルドや開発用スクリプトは、これらが足りない場合にセットアップコマンドを表示します。

### Zig によるクロスコンパイル

リリース CI では [Zig](https://ziglang.org/)
を Rust の明示的なクロスターゲット向け C リンカードライバーとして使います。ローカルで同じビルドを行う場合は、Zig をインストールし、Rust ターゲットを追加してください。

```sh
rustup target add aarch64-unknown-linux-gnu
cargo build --manifest-path apps/sl/Cargo.toml --release --target aarch64-unknown-linux-gnu
```

チェックインされた Cargo 設定は Linux GNU クロスターゲットに Zig を使います。CI では Windows の `x86_64-pc-windows-gnu`
と `aarch64-pc-windows-gnullvm` ビルドに `cargo-zigbuild` を使い、MSVC 固有のコンパイルを避けます。
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,16 @@ bun run setup

`bun run setup` installs the Rust `wasm32-unknown-unknown` target and `wasm-pack`, which are required by the website
build. The build and dev scripts also check for these prerequisites and print the setup command if anything is missing.

### Cross-compiling with Zig

Release CI uses [Zig](https://ziglang.org/) as the C linker driver for explicit Rust cross targets. Install Zig and add
the Rust target before building locally:

```sh
rustup target add aarch64-unknown-linux-gnu
cargo build --manifest-path apps/sl/Cargo.toml --release --target aarch64-unknown-linux-gnu
```

The checked-in Cargo config uses Zig for Linux GNU cross targets. CI uses `cargo-zigbuild` for Windows
`x86_64-pc-windows-gnu` and `aarch64-pc-windows-gnullvm` builds, avoiding MSVC-specific compilation.
Loading
Loading