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
179 changes: 179 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
name: CI

on:
pull_request:
push:
branches:
- main
workflow_dispatch:

permissions:
contents: read

env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

jobs:
flake:
name: Nix flake
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6

- uses: DeterminateSystems/determinate-nix-action@v3

- name: Evaluate flake
run: nix flake check --no-build

native:
name: Native C++
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6

- uses: DeterminateSystems/determinate-nix-action@v3

- name: Configure and build
run: |
nix develop .#native --command bash -c '
set -euo pipefail
cmake --preset linux-release
cmake --build --preset linux-release --parallel
cmake --install out/build/linux-release --prefix out/install/linux-release
'

- name: Upload native artifact
uses: actions/upload-artifact@v7
with:
name: ysmparser-linux-native
path: out/install/linux-release/
if-no-files-found: error

web:
name: Browser WASM
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6

- uses: DeterminateSystems/determinate-nix-action@v3

- name: Build browser app
run: nix develop .#wasm --command bash public/scripts/build-web.sh

- name: Upload web artifact
uses: actions/upload-artifact@v7
with:
name: ysmparser-web
path: public/dist/
if-no-files-found: error

tauri:
name: Tauri desktop
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6

- uses: DeterminateSystems/determinate-nix-action@v3

- name: Build sidecar and Tauri shell
run: |
nix develop .#tauri --command bash -c '
set -euo pipefail
cmake -S . -B build-cpp -G Ninja -DCMAKE_BUILD_TYPE=Release -DYSM_TARGET_JNI=OFF
cmake --build build-cpp --parallel
mkdir -p public/src-tauri/binaries
cp build-cpp/YSMParser/YSMParser public/src-tauri/binaries/YSMParser-x86_64-unknown-linux-gnu
chmod +x public/src-tauri/binaries/YSMParser-x86_64-unknown-linux-gnu
cd public
pnpm install --frozen-lockfile
pnpm build
cargo build --manifest-path src-tauri/Cargo.toml --locked --release
'

- name: Upload Tauri artifact
uses: actions/upload-artifact@v7
with:
name: ysmparser-tauri-linux
path: public/src-tauri/target/release/ysm-parser
if-no-files-found: error

tauri-windows-macos:
name: Tauri desktop (${{ matrix.label }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- label: Windows x64
os: windows-2022
msvc_arch: x64
sidecar_source: build-cpp/YSMParser/YSMParser.exe
sidecar_name: YSMParser-x86_64-pc-windows-msvc.exe
bundles: nsis
artifact_name: ysmparser-tauri-windows-x64
- label: macOS arm64
os: macos-14
sidecar_source: build-cpp/YSMParser/YSMParser
sidecar_name: YSMParser-aarch64-apple-darwin
bundles: dmg
artifact_name: ysmparser-tauri-macos-arm64
steps:
- uses: actions/checkout@v6

- uses: seanmiddleditch/gha-setup-ninja@v5

- name: Setup MSVC environment
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.msvc_arch }}

- name: Configure Rust MSVC linker
if: runner.os == 'Windows'
shell: pwsh
run: |
$linker = Join-Path $env:VCToolsInstallDir 'bin\Hostx64\x64\link.exe'
if (-not (Test-Path $linker)) {
throw "MSVC linker not found: $linker"
}
"CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER=$linker" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
Write-Host "Using Rust MSVC linker: $linker"

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 11

- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: pnpm
cache-dependency-path: public/pnpm-lock.yaml

- name: Build sidecar and Tauri bundle
shell: bash
run: |
set -euo pipefail
cmake -S . -B build-cpp -G Ninja -DCMAKE_BUILD_TYPE=Release -DYSM_TARGET_JNI=OFF
cmake --build build-cpp --parallel
mkdir -p public/src-tauri/binaries
cp "${{ matrix.sidecar_source }}" "public/src-tauri/binaries/${{ matrix.sidecar_name }}"
if [[ "${{ runner.os }}" != "Windows" ]]; then
chmod +x "public/src-tauri/binaries/${{ matrix.sidecar_name }}"
fi
cd public
pnpm install --frozen-lockfile
pnpm tauri build --bundles "${{ matrix.bundles }}"

- name: Upload Tauri bundle
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.artifact_name }}
path: |
public/src-tauri/target/release/bundle/nsis/*.exe
public/src-tauri/target/release/bundle/dmg/*.dmg
if-no-files-found: error
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"cSpell.words": [
"BLOCKBENCH",
"Blockbench's",
"initialised",
"openysm",
"tauri",
"ysmparser"
]
}
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ string(STRIP "${YSM_PARSER_VERSION_RAW}" YSM_PARSER_VERSION)
project("YSMParser" VERSION ${YSM_PARSER_VERSION})

option(YSM_TARGET_WASM "Build a WebAssembly/Node.js target with Emscripten" OFF)
option(YSM_WASM_SIMD "Enable WebAssembly SIMD code generation" OFF)
set(YSM_WASM_ENV "node" CACHE STRING "Emscripten runtime environment (node or web)")
set_property(CACHE YSM_WASM_ENV PROPERTY STRINGS node web)

Expand Down
4 changes: 3 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_TOOLCHAIN_FILE": "$env{EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake",
"YSM_TARGET_WASM": "ON"
"CMAKE_CXX_SCAN_FOR_MODULES": "OFF",
"YSM_TARGET_WASM": "ON",
"YSM_WASM_SIMD": "OFF"
}
},
{
Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,24 @@ WASM构建需要EMSDK环境变量指向Emscripten安装目录。
| `json` |
| `CLI11` |

### 新前端构建(/public)

```bash
# 安装依赖
cd public && pnpm install

# 网页端(静态文件)
pnpm build
# 构建输出在 public/dist/,将 YSMParser.js 和 YSMParser.wasm (wasm-web-release 构建产物) 一起放入即可使用

# Tauri 桌面应用(开发模式)
pnpm tauri dev

# Tauri 桌面应用(发行构建)
# 先将 YSMParser 可执行文件放入 public/src-tauri/binaries/YSMParser-<target-triple>
pnpm tauri build
```

<a id="english"></a>

## English
Expand Down Expand Up @@ -269,3 +287,22 @@ All dependencies are vendored in source form under `external`.
| `fpng` |
| `json` |
| `CLI11` |

### New Frontend Build (/public)

```bash
# Install dependencies
cd public && pnpm install

# Web service (static files)
pnpm build
# Output is in public/dist/ — place YSMParser.js and YSMParser.wasm
# (from the wasm-web-release build) alongside it before serving

# Tauri desktop app (development)
pnpm tauri dev

# Tauri desktop app (release build)
# First copy the YSMParser binary to public/src-tauri/binaries/YSMParser-<target-triple>
pnpm tauri build
```
12 changes: 12 additions & 0 deletions YSMParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,25 @@ if (YSM_TARGET_WASM)
"-fexceptions"
)

if (YSM_WASM_SIMD)
target_compile_options(YSMParser PRIVATE
"-msimd128"
)
endif()

target_link_options(YSMParser PRIVATE
"-fexceptions"
"-sFORCE_FILESYSTEM=1"
"-sALLOW_MEMORY_GROWTH=1"
"-sEXIT_RUNTIME=0"
)

if (YSM_WASM_SIMD)
target_link_options(YSMParser PRIVATE
"-msimd128"
)
endif()

if (YSM_WASM_ENV STREQUAL "node")
target_link_options(YSMParser PRIVATE
"-sENVIRONMENT=node"
Expand Down
Loading