Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
714c0c4
Add basic LLVM backend scaffolding
MaxDesiatov Jan 5, 2026
bdb4dce
Bump CMake to 3.30.2 in CMake GHA workflow
MaxDesiatov Jan 5, 2026
e653a99
Add LLVM build step scaffolding
MaxDesiatov Jan 5, 2026
c8ea165
Update `.github/workflows/main.yml`
MaxDesiatov Jan 5, 2026
13b5d27
Refine LLVM build steps in CI workflow
MaxDesiatov Jan 5, 2026
ce9c98f
Install Python 3 when building LLVM
MaxDesiatov Jan 5, 2026
8b4f17d
Disable LLVM build commands in main.yml
MaxDesiatov Jan 5, 2026
ea4f6a4
Refactor LLVM build directory and commands
MaxDesiatov Jan 5, 2026
4261974
Update main.yml
MaxDesiatov Jan 5, 2026
60f09ef
Add X86/AArch64 matrix for LLVM build
MaxDesiatov Jan 5, 2026
eebd6bc
Add `aarch64` to LLVM build matrix for CMake installation
MaxDesiatov Jan 5, 2026
28fe7ff
Add caching for LLVM in GitHub Actions workflow
MaxDesiatov Jan 5, 2026
4cbbca3
Fix libc imports in `LLVMBackend/Loader.swift`
MaxDesiatov Jan 5, 2026
913626f
Fix Linux build issues, use fresh LLVM tag from `swiftlang
MaxDesiatov Jan 5, 2026
82125ac
Link x86 LLVM components when building on x86
MaxDesiatov Jan 5, 2026
01b7414
Re-enable existing CI jobs
MaxDesiatov Jan 5, 2026
954f905
Rename `LLVMBackendCLI` to `wasmkit-llvm`, add `swift-collections` dep
MaxDesiatov Jan 6, 2026
b0239f4
Fix `SwiftCollections` typo in `FetchContent` block
MaxDesiatov Jan 6, 2026
216a4aa
CMake: explicitly pass `-module-name` for `wasmkit-llvm` target
MaxDesiatov Jan 6, 2026
d69db0a
Replace `UMBP` with `RigidArray` in `CodegenContext`
MaxDesiatov Jan 6, 2026
15045ba
Make `IRFunctionVisitor` noncopyable
MaxDesiatov Jan 6, 2026
626ebd9
Move CLI command types into a library for reuse in `LLVMBackendCLI` m…
MaxDesiatov Jan 6, 2026
5efa281
Fix SwiftPM build
MaxDesiatov Jan 6, 2026
13b2df6
Fix `libswiftCompatibilitySpan.dylib` path on macOS
MaxDesiatov Jan 6, 2026
ce9600c
Fix `RigidArray` OOB in `CodegenContext`
MaxDesiatov Jan 6, 2026
61454ea
Fix missing comma in `Package.swift`
MaxDesiatov Jan 6, 2026
9c40c5d
Fix formatting
MaxDesiatov Jan 6, 2026
c88f97b
Enable a simple smoke test setup for `factorial.wat`
MaxDesiatov Jan 6, 2026
539811a
Fix formatting
MaxDesiatov Jan 6, 2026
99dd706
Add support for Linux in `LLVMBackend/Linker.swift`
MaxDesiatov Jan 6, 2026
4bbc706
Add macOS 15 builds for LLVM configuration
MaxDesiatov Jan 6, 2026
0664784
Separate Ubuntu and macOS build jobs for LLVM
MaxDesiatov Jan 6, 2026
ae44485
Shell uses `fi` instead of `endif`
MaxDesiatov Jan 6, 2026
87a6f38
Try bash-compatible if-else syntax
MaxDesiatov Jan 6, 2026
376cb68
Explicitly use bash for Ubuntu LLVM job
MaxDesiatov Jan 6, 2026
0efa596
Remove unused files
MaxDesiatov Jan 6, 2026
8a59391
Lower requirement in top-level `CMakeLists.txt` to Swift 6.1
MaxDesiatov Jan 6, 2026
229138b
Remove macOS 14 LLVM target from workflow
MaxDesiatov Jan 6, 2026
b4fe009
`main.yml` workflow: diagnose macOS CMake configuration failure
MaxDesiatov Jan 6, 2026
884bae9
`main.yml` workflow: use Xcode 26.1 to get `-print-target-info`
MaxDesiatov Jan 6, 2026
9f4a9c5
`main.yml` workflow: bump macOS to 26 for LLVM build
MaxDesiatov Jan 6, 2026
f263c70
Raise CMake `min_supported_swift_version` back to 6.2
MaxDesiatov Jan 6, 2026
da4dbea
Make CLI commands reusable with new `CLICommands` module
MaxDesiatov Jan 7, 2026
2748b4e
Merge branch 'maxd/cli-commands' of github.com:swiftwasm/WasmKit into…
MaxDesiatov Jan 7, 2026
a6aede1
CMake: remove duplicated `FetchContent(ArgumentParser...)`
MaxDesiatov Jan 7, 2026
8d845ec
Fix `wasmkit` executable naming in `main.yml` GHA workflow
MaxDesiatov Jan 7, 2026
e10245d
Merge branch 'maxd/cli-commands' of github.com:swiftwasm/WasmKit into…
MaxDesiatov Jan 7, 2026
58634fc
CMake: remove duplicated `FetchContent(ArgumentParser...)`
MaxDesiatov Jan 7, 2026
f8b30cb
Merge branch 'maxd/cli-commands' into maxd/llvm-backend-cmake
MaxDesiatov Jan 7, 2026
33f8769
Delete Sources/CLICommands/Parse.swift
MaxDesiatov Jan 7, 2026
8c2b599
Delete Sources/CLI/DebuggerServer.swift
MaxDesiatov Jan 7, 2026
f336d0e
Merge branch 'maxd/cli-commands' of github.com:swiftwasm/WasmKit into…
MaxDesiatov Jan 7, 2026
000e378
Merge branch 'main' of github.com:swiftwasm/WasmKit into maxd/llvm-ba…
MaxDesiatov Jan 10, 2026
88a0a39
Move dependencies to top-level CMakeLists.txt
MaxDesiatov Jan 10, 2026
5936942
Merge branch 'main' into maxd/llvm-backend-cmake
MaxDesiatov Jan 25, 2026
8bd1bde
Fix trailing comma
MaxDesiatov Jan 26, 2026
d0bfb95
LLVM: fix exported functions not callable by name (#250)
MaxDesiatov Jan 26, 2026
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
89 changes: 88 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,98 @@ jobs:
- name: Install CMake
run: |
apt-get install -y curl
curl -L https://github.com/Kitware/CMake/releases/download/v3.29.2/cmake-3.29.2-linux-x86_64.tar.gz | tar xz --strip-component 1 -C /usr/local/
curl -L https://github.com/Kitware/CMake/releases/download/v3.30.2/cmake-3.30.2-linux-x86_64.tar.gz | tar xz --strip-component 1 -C /usr/local/
- run: cmake -G Ninja -B ./build
- run: cmake --build ./build
- run: ./build/bin/wasmkit --version

build-llvm-ubuntu:
strategy:
matrix:
include:
- os: ubuntu-24.04
llvm-target: X86
- os: ubuntu-24.04-arm
llvm-target: AArch64
runs-on: ${{ matrix.os }}
container:
image: swift:6.2-noble
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: apt-get update && apt-get install -y ninja-build python3
- name: Install CMake
run: |
apt-get install -y curl
if [[ "${{ matrix.llvm-target }}" == "AArch64" ]]; then
export CMAKE_ARCH=aarch64
elif [[ "${{ matrix.llvm-target }}" == "X86" ]]; then
export CMAKE_ARCH=x86_64
else
exit 1
fi

curl -L "https://github.com/Kitware/CMake/releases/download/v3.30.2/cmake-3.30.2-linux-${CMAKE_ARCH}.tar.gz" | tar xz --strip-component 1 -C /usr/local/
- name: Cache LLVM
id: cache-llvm
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/Vendor/llvm-project
# IMPORTANT: Update the key when updating LLVM tag below in the build step.
key: llvm-${{ matrix.os }}-${{ matrix.llvm-target }}-swift-main-2026-01-04
- name: Build LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
mkdir -p $GITHUB_WORKSPACE/Vendor/llvm-project
curl -L https://github.com/swiftlang/llvm-project/archive/refs/tags/swift-DEVELOPMENT-SNAPSHOT-2026-01-04-a.tar.gz | tar xz --strip-component 1 -C $GITHUB_WORKSPACE/Vendor/llvm-project
cmake -DLLVM_TARGETS_TO_BUILD=${{ matrix.llvm-target }} -DLLVM_INCLUDE_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -G Ninja -S $GITHUB_WORKSPACE/Vendor/llvm-project/llvm -B $GITHUB_WORKSPACE/Vendor/llvm-project/llvm/build
cmake --build $GITHUB_WORKSPACE/Vendor/llvm-project/llvm/build
- name: Build WasmKit with LLVM
run: |
LLVM_DIR="$GITHUB_WORKSPACE/Vendor/llvm-project/llvm/build/lib/cmake/llvm/" cmake -DWASMKIT_BUILD_LLVM_BACKEND=ON -DWASMKIT_LLVM_BACKEND_TARGET=${{ matrix.llvm-target }} -DWASMKIT_BUILD_CLI=ON -G Ninja -B ./build
cmake --build ./build
- name: Run a smoke test
run: |
./build/bin/wasmkit-llvm wat2wasm Examples/wasm/factorial.wat
./build/bin/wasmkit-llvm run Examples/wasm/factorial.wasm fac i64:5

build-llvm-macos:
strategy:
matrix:
include:
- os: macos-26
llvm-target: AArch64

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Cache LLVM
id: cache-llvm
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/Vendor/llvm-project
# IMPORTANT: Update the key when updating LLVM tag below in the build step.
key: llvm-${{ matrix.os }}-${{ matrix.llvm-target }}-swift-main-2026-01-04
- name: Build LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
sudo xcode-select -s /Applications/Xcode_26.2.app
mkdir -p $GITHUB_WORKSPACE/Vendor/llvm-project
curl -L https://github.com/swiftlang/llvm-project/archive/refs/tags/swift-DEVELOPMENT-SNAPSHOT-2026-01-04-a.tar.gz | tar xz --strip-component 1 -C $GITHUB_WORKSPACE/Vendor/llvm-project
cmake -DLLVM_TARGETS_TO_BUILD=${{ matrix.llvm-target }} -DLLVM_INCLUDE_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -G Ninja -S $GITHUB_WORKSPACE/Vendor/llvm-project/llvm -B $GITHUB_WORKSPACE/Vendor/llvm-project/llvm/build
cmake --build $GITHUB_WORKSPACE/Vendor/llvm-project/llvm/build
- name: Build WasmKit with LLVM
run: |
LLVM_DIR="$GITHUB_WORKSPACE/Vendor/llvm-project/llvm/build/lib/cmake/llvm/" cmake -DWASMKIT_BUILD_LLVM_BACKEND=ON -DWASMKIT_LLVM_BACKEND_TARGET=${{ matrix.llvm-target }} -DWASMKIT_BUILD_CLI=ON -G Ninja -B ./build
cmake --build ./build
- name: Run a smoke test
run: |
./build/bin/wasmkit-llvm wat2wasm Examples/wasm/factorial.wat
./build/bin/wasmkit-llvm run Examples/wasm/factorial.wasm fac i64:5

build-wasi:
runs-on: ubuntu-24.04
container:
Expand Down
63 changes: 52 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
cmake_minimum_required(VERSION 3.19.6)
cmake_minimum_required(VERSION 3.30)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)

project(WasmKit LANGUAGES C Swift)
project(WasmKit LANGUAGES C CXX Swift)

set(SWIFT_VERSION 5)
set(SWIFT_VERSION 6)
set(CMAKE_Swift_LANGUAGE_VERSION ${SWIFT_VERSION})

set(min_supported_swift_version 6.2)
if(CMAKE_Swift_COMPILER_VERSION VERSION_LESS "${min_supported_swift_version}")
message(
FATAL_ERROR
"Outdated Swift compiler: "
"Swift ${min_supported_swift_version} or newer is required."
)
endif()

# Enable whole module optimization for Release or RelWithDebInfo builds.
if(POLICY CMP0157)
set(CMAKE_Swift_COMPILATION_MODE $<IF:$<CONFIG:Release,RelWithDebInfo>,wholemodule,incremental>)
else()
add_compile_options($<$<AND:$<COMPILE_LANGUAGE:Swift>,$<CONFIG:Release,RelWithDebInfo>>:-wmo>)
endif()

if(CMAKE_VERSION VERSION_LESS 3.21)
get_property(parent_dir DIRECTORY PROPERTY PARENT_DIRECTORY)
if(NOT parent_dir)
set(PROJECT_IS_TOP_LEVEL TRUE)
endif()
endif()

# The subdirectory into which host libraries will be installed.
set(SWIFT_HOST_LIBRARIES_SUBDIRECTORY "swift/host")

Expand Down Expand Up @@ -52,7 +54,9 @@ add_compile_definitions(

include(FetchContent)

option(WASMKIT_BUILD_CLI "Build wasmkit-cli" ON)
option(WASMKIT_BUILD_CLI "Build WasmKit CLI" ON)
option(WASMKIT_BUILD_LLVM_BACKEND "Build WasmKit LLVM backend (experimental)" OFF)
option(WASMKIT_LLVM_BACKEND_TARGET "WasmKit LLVM backend target architecture" "aarch64")

if(WASMKIT_BUILD_CLI)
set(BUILD_TESTING OFF) # disable ArgumentParser tests
Expand All @@ -67,6 +71,43 @@ if(WASMKIT_BUILD_CLI)
endif()
endif()

if(WASMKIT_BUILD_LLVM_BACKEND)
FetchContent_Declare(
SwiftLLVMBindings
GIT_REPOSITORY "https://github.com/swiftlang/swift-llvm-bindings.git"
GIT_TAG c1fffb92d4f9d7cb98800762631cfa354869fb46
GIT_SHALLOW TRUE
GIT_PROGRESS ON
)

FetchContent_MakeAvailable(SwiftLLVMBindings)

find_package(Subprocess CONFIG)

if(NOT Subprocess_FOUND)
message("-- Vending Subprocess")
FetchContent_Declare(
Subprocess
GIT_REPOSITORY https://github.com/swiftlang/swift-subprocess
GIT_TAG 0.2.1
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(Subprocess)
endif()

find_package(SwiftCollections CONFIG)
if(NOT SwiftCollections_FOUND)
message("-- Vending SwiftCollections")
FetchContent_Declare(
SwiftCollections
GIT_REPOSITORY https://github.com/apple/swift-collections
GIT_TAG 1.3.0
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(SwiftCollections)
endif()
endif()

find_package(SwiftSystem CONFIG)
if(NOT SwiftSystem_FOUND)
message("-- Vending SwiftSystem")
Expand Down
14 changes: 1 addition & 13 deletions Sources/CLICommands/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,4 @@ add_wasmkit_library(CLICommands
)

target_link_wasmkit_libraries(CLICommands PUBLIC
WAT WasmKitWASI)

add_dependencies(
CLICommands

ArgumentParser
)

target_link_libraries(CLICommands

PUBLIC
ArgumentParser
)
ArgumentParser WAT WasmKitWASI)
9 changes: 9 additions & 0 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ if(WASMKIT_BUILD_CLI)
add_subdirectory(CLI)
add_subdirectory(CLICommands)
endif()

if(WASMKIT_BUILD_LLVM_BACKEND)
add_subdirectory(LLVMInterop)
add_subdirectory(LLVMBackend)

if(WASMKIT_BUILD_CLI)
add_subdirectory(LLVMBackendCLI)
endif()
endif()
42 changes: 42 additions & 0 deletions Sources/LLVMBackend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
add_library(
LLVMBackend

CodegenContext.swift
IRContext+codegen.swift
IRFunctionVisitor.swift
Linker.swift
Loader.swift
Wasm32Memory.swift
)
target_compile_options(
LLVMBackend
PUBLIC
"SHELL:-Xcc -std=c++17"
"SHELL:-Xcc -fapinotes"
"SHELL:-Xcc -fapinotes-modules"
"-cxx-interoperability-mode=default"
-package-name WasmKitPackage
)

target_include_directories(
LLVMBackend
PUBLIC
"${LLVMINTEROP_INCLUDE_DIR}"
"${LLVM_MAIN_INCLUDE_DIR}"
"${LLVM_INCLUDE_DIR}"
)

set(WASMKIT_DEPENDENCIES WAT WasmKit WasmTypes WasmParser)
set(BUILD_TESTING OFF)

add_dependencies(LLVMInterop BasicContainers LLVM_Utils Subprocess ${WASMKIT_DEPENDENCIES})

target_link_libraries(
LLVMBackend

BasicContainers
${WASMKIT_DEPENDENCIES}
LLVMInterop
LLVM_Utils
Subprocess
)
Loading
Loading