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
32 changes: 32 additions & 0 deletions .github/actions/setup-emscripten/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Setup Emscripten SDK
description: Install and activate a pinned Emscripten SDK for workflow builds.

inputs:
version:
description: Emscripten SDK version to install.
required: true

runs:
using: composite
steps:
- name: Cache Emscripten SDK
uses: actions/cache@v4
with:
path: ${{ runner.tool_cache }}/emsdk-${{ inputs.version }}
key: emsdk-${{ runner.os }}-${{ inputs.version }}

- name: Install Emscripten SDK
shell: bash
run: |
set -euo pipefail
emsdk_root="${RUNNER_TOOL_CACHE}/emsdk-${{ inputs.version }}"
if [ ! -d "${emsdk_root}/.git" ]; then
rm -rf "${emsdk_root}"
git clone --filter=blob:none --no-recurse-submodules https://github.com/emscripten-core/emsdk.git "${emsdk_root}"
fi
git -C "${emsdk_root}" reset --hard
git -C "${emsdk_root}" fetch --depth=1 origin "refs/tags/${{ inputs.version }}"
git -C "${emsdk_root}" checkout --detach FETCH_HEAD
"${emsdk_root}/emsdk" install "${{ inputs.version }}"
"${emsdk_root}/emsdk" activate "${{ inputs.version }}"
echo "EMSDK=${emsdk_root}" >> "${GITHUB_ENV}"
31 changes: 30 additions & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ concurrency:
env:
ASTRO_SITE: https://vide.pascal-lab.net
OSSUTIL_VERSION: 1.7.18
EMSDK_VERSION: 5.0.2

jobs:
deploy-preview:
Expand Down Expand Up @@ -251,13 +252,41 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Rust
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt

- name: Rust Cache
uses: Swatinem/rust-cache@v2
continue-on-error: true
with:
shared-key: docs-wasm-${{ runner.os }}-${{ env.EMSDK_VERSION }}
cache-workspace-crates: true
cache-on-failure: true

- name: Install Emscripten SDK
uses: ./.github/actions/setup-emscripten
with:
version: ${{ env.EMSDK_VERSION }}

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: docs/package-lock.json
cache-dependency-path: |
docs/package-lock.json
playground/package-lock.json

- name: Build playground WASM
run: |
source "${EMSDK}/emsdk_env.sh"
npm run build:wasm
working-directory: playground

- name: Install dependencies
run: npm ci
Expand Down
37 changes: 36 additions & 1 deletion .github/workflows/docs-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ on:
branches: [master]
paths:
- "docs/**"
- "playground/**"
- "crates/vizsla-lsp-wasm/**"
- ".github/actions/setup-emscripten/**"
- ".github/workflows/docs-preview.yml"
- ".github/workflows/deploy-docs.yml"
pull_request:
types: [opened, synchronize, reopened, closed]
paths:
- "docs/**"
- "playground/**"
- "crates/vizsla-lsp-wasm/**"
- ".github/actions/setup-emscripten/**"
- ".github/workflows/docs-preview.yml"
- ".github/workflows/deploy-docs.yml"

Expand All @@ -21,6 +27,7 @@ env:
ASTRO_SITE: https://vide.pascal-lab.net
ASTRO_BASE: ${{ github.event_name == 'pull_request' && format('/preview/pr-{0}/', github.event.pull_request.number) || '/' }}
PREVIEW_URL: ${{ github.event_name == 'pull_request' && format('https://vide.pascal-lab.net/preview/pr-{0}/', github.event.pull_request.number) || '' }}
EMSDK_VERSION: 5.0.2

jobs:
metadata:
Expand Down Expand Up @@ -64,13 +71,41 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Rust
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt

- name: Rust Cache
uses: Swatinem/rust-cache@v2
continue-on-error: true
with:
shared-key: docs-wasm-${{ runner.os }}-${{ env.EMSDK_VERSION }}
cache-workspace-crates: true
cache-on-failure: true

- name: Install Emscripten SDK
uses: ./.github/actions/setup-emscripten
with:
version: ${{ env.EMSDK_VERSION }}

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: docs/package-lock.json
cache-dependency-path: |
docs/package-lock.json
playground/package-lock.json

- name: Build playground WASM
run: |
source "${EMSDK}/emsdk_env.sh"
npm run build:wasm
working-directory: playground

- name: Install dependencies
run: npm ci
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tags

# generated files
generated.rs
docs/public/vizsla-lab/

.DS_Store
.vscode/
Expand Down
18 changes: 12 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ utils.workspace = true
vfs-notify.workspace = true
vfs.workspace = true

always-assert = "0.1.3"
always-assert.workspace = true
anyhow.workspace = true
clap = { version = "4.4.6", features = ["derive"] }
const_format.workspace = true
crossbeam-channel.workspace = true
dunce.workspace = true
itertools.workspace = true
la-arena.workspace = true
lsp-server = "0.7.6"
lsp-types = "0.95.0"
lsp-server.workspace = true
lsp-types.workspace = true
nohash-hasher.workspace = true
num_cpus = "1.16.0"
num_cpus.workspace = true
parking_lot = "0.12.1"
regex.workspace = true
rustc-hash.workspace = true
serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true
toml = "0.9.8"
toml.workspace = true
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["registry", "fmt", "tracing-log",] }
tracing-chrome = "0.7.2"
tracing.workspace = true
Expand All @@ -69,6 +69,7 @@ slang = { path = "./crates/slang", version = "0.0.1" }
parking_lot = "0.12.1"


always-assert = "0.1.3"
anyhow = "1.0.75"
bitflags = "2.9.0"
camino = "1.1.6"
Expand All @@ -79,8 +80,11 @@ either = "1.9.0"
globset = "0.4.16"
itertools = "0.14.0"
la-arena = "0.3.1"
lsp-server = "0.7.6"
lsp-types = "0.95.0"
memchr = "2.7.1"
nohash-hasher = "0.2.0"
num_cpus = "1.16.0"
regex = "1.10.2"
rustc-hash = "2.1.1"
salsa = "0.17.0-pre.2"
Expand All @@ -95,8 +99,10 @@ smol_str = { version = "0.3.1", features = ["serde"] }
tempfile = "3.27.0"
text-size = "1.1.1"
thiserror = "2.0.0"
toml = "0.9.8"
tracing = "0.1.37"
triomphe = "0.1.9"
winapi = "0.3.9"

[profile.dev]
debug = 1
Expand All @@ -120,7 +126,7 @@ inherits = "release"
lto = true

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3.9" }
winapi.workspace = true

[dev-dependencies]
utils = { workspace = true, features = ["test-support"] }
Expand Down
37 changes: 28 additions & 9 deletions crates/slang/bindings/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fn generate_cxx_bridge() -> PathBuf {

fn build_cpp_lib(cxxbridge_dir: &Path, debug: bool) -> PathBuf {
let cmake_profile = if debug { "Debug" } else { "Release" };
let emscripten = env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("emscripten");

// Configure CMake build
let config = &mut cmake::Config::new(".");
Expand All @@ -38,11 +39,26 @@ fn build_cpp_lib(cxxbridge_dir: &Path, debug: bool) -> PathBuf {
.define("SLANG_INCLUDE_PYLIB", "OFF")
.define("SLANG_INCLUDE_RUSTLIB", "ON")
.define("SLANG_RUST_CXXBRIDGE_DIR", cxxbridge_dir.to_string_lossy().as_ref())
.define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreadedDLL")
.profile(cmake_profile)
.define("CMAKE_VERBOSE_MAKEFILE", "ON");

if !debug && cfg!(target_env = "msvc") {
if !emscripten {
config.define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreadedDLL");
}

if emscripten {
config
.define("SLANG_USE_MIMALLOC", "OFF")
.define("CMAKE_TRY_COMPILE_TARGET_TYPE", "STATIC_LIBRARY")
.define("CMAKE_CXX_FLAGS", "-fwasm-exceptions -include cstdlib")
.define("CMAKE_CXX_FLAGS_RELEASE", "-O2 -DNDEBUG")
.define("CMAKE_C_FLAGS_RELEASE", "-O2 -DNDEBUG");
if let Ok(toolchain_file) = env::var("EMSCRIPTEN_CMAKE_TOOLCHAIN_FILE") {
config.define("CMAKE_TOOLCHAIN_FILE", toolchain_file);
}
}

if !emscripten && !debug && cfg!(target_env = "msvc") {
// cmake-rs still sets config-specific MSVC flags for Visual Studio
// generators to preserve /MD or /MT. That replaces CMake's built-in
// Release defaults, while cmake-rs has already filtered optimization
Expand All @@ -59,19 +75,22 @@ fn build_cpp_lib(cxxbridge_dir: &Path, debug: bool) -> PathBuf {

fn setup_linking(install_dir: &Path, debug: bool) {
let lib_dir = install_dir.join("lib");
let emscripten = env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("emscripten");
let fmt_lib = if debug { "fmtd" } else { "fmt" };
let mimalloc_lib = if cfg!(target_env = "msvc") {
if debug { "mimalloc-static-debug" } else { "mimalloc-static" }
} else {
if debug { "mimalloc-debug" } else { "mimalloc" }
};

println!("cargo:rustc-link-search=native={}", lib_dir.display());
println!("cargo:rustc-link-lib=static:+whole-archive,-bundle=slang_rust_bridge");
println!("cargo:rustc-link-lib=static:-bundle=svlang");
println!("cargo:rustc-link-lib=static:-bundle={}", fmt_lib);
println!("cargo:rustc-link-lib=static:-bundle={}", mimalloc_lib);
if cfg!(target_os = "windows") {
if !emscripten {
let mimalloc_lib = if cfg!(target_env = "msvc") {
if debug { "mimalloc-static-debug" } else { "mimalloc-static" }
} else {
if debug { "mimalloc-debug" } else { "mimalloc" }
};
println!("cargo:rustc-link-lib=static:-bundle={}", mimalloc_lib);
}
if !emscripten && cfg!(target_os = "windows") {
// mimalloc's Windows large-page support pulls in these token APIs.
println!("cargo:rustc-link-lib=dylib=Advapi32");
}
Expand Down
3 changes: 3 additions & 0 deletions crates/slang/bindings/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,10 @@ impl fmt::Display for Bit {
}

impl SourceLocation {
#[cfg(target_pointer_width = "64")]
const NO_LOCATION: usize = (1usize << 36) - 1;
#[cfg(target_pointer_width = "32")]
const NO_LOCATION: usize = usize::MAX;

#[inline]
pub fn from_unique_ptr(_ptr: UniquePtr<ffi::SourceLocation>) -> Option<Self> {
Expand Down
6 changes: 6 additions & 0 deletions crates/slang/external/boost_unordered.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
#include <utility>
#include <variant>

#if defined(__EMSCRIPTEN__)
namespace boost {
using uint16_t = std::uint16_t;
}
#endif

#pragma once

// This is a minimal header that contains only the small set
Expand Down
4 changes: 2 additions & 2 deletions crates/slang/include/slang/parsing/Token.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class SLANG_EXPORT Trivia {

Trivia clone(BumpAllocator& alloc, bool deep = false) const;
};
#if !defined(_M_IX86) && !defined(__clang_analyzer__)
#if !defined(_M_IX86) && !defined(__EMSCRIPTEN__) && !defined(__clang_analyzer__)
static_assert(sizeof(Trivia) == 16);
#endif

Expand Down Expand Up @@ -220,7 +220,7 @@ class SLANG_EXPORT Token {
static constexpr int MaxTriviaSmallCount = (1 << 4) - 2;
};

#if !defined(_M_IX86)
#if !defined(_M_IX86) && !defined(__EMSCRIPTEN__)
static_assert(sizeof(Token) == 16);
#endif
static_assert(std::is_trivially_copyable_v<Token>);
Expand Down
Loading
Loading