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
104 changes: 104 additions & 0 deletions .github/workflows/build-native.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Build Native Libraries

on:
workflow_dispatch:
inputs:
create_release:
description: 'Create a GitHub release with the built artifacts'
required: false
type: boolean
default: false
push:
tags:
- "wasm_run-v*"

permissions:
contents: write

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable

- name: Install cross-rs
run: cargo install cross --git https://github.com/cross-rs/cross

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Check disk space
run: df -h

- name: Build all native libraries
run: |
cd packages/wasm_run/native
./scripts/cross-build.sh --all --keep-images
timeout-minutes: 60

- name: Package libraries for release
run: |
cd packages/wasm_run/native/lib

# Create release directory
mkdir -p ../release

# Package Android libraries (jniLibs structure)
mkdir -p jniLibs/arm64-v8a jniLibs/armeabi-v7a jniLibs/x86_64 jniLibs/x86
cp aarch64-linux-android/libwasm_run_native.so jniLibs/arm64-v8a/
cp armv7-linux-androideabi/libwasm_run_native.so jniLibs/armeabi-v7a/
cp x86_64-linux-android/libwasm_run_native.so jniLibs/x86_64/
cp i686-linux-android/libwasm_run_native.so jniLibs/x86/
tar -czvf ../release/android.tar.gz -C jniLibs .
rm -rf jniLibs

# Package macOS libraries
mkdir -p macos-arm64 macos-x64
cp aarch64-apple-darwin/libwasm_run_native.dylib macos-arm64/
cp x86_64-apple-darwin/libwasm_run_native.dylib macos-x64/
tar -czvf ../release/macos.tar.gz macos-arm64 macos-x64
rm -rf macos-arm64 macos-x64

# Package Linux libraries
mkdir -p linux-arm64 linux-x64
cp aarch64-unknown-linux-gnu/libwasm_run_native.so linux-arm64/
cp x86_64-unknown-linux-gnu/libwasm_run_native.so linux-x64/
tar -czvf ../release/linux.tar.gz linux-arm64 linux-x64
rm -rf linux-arm64 linux-x64

# Package Windows libraries
mkdir -p windows-x64
cp x86_64-pc-windows-gnu/wasm_run_native.dll windows-x64/
tar -czvf ../release/windows.tar.gz windows-x64
rm -rf windows-x64

# Package iOS library
mkdir -p ios-arm64
cp aarch64-apple-ios/libwasm_run_native.dylib ios-arm64/
tar -czvf ../release/ios.tar.gz ios-arm64
rm -rf ios-arm64

# List release artifacts
ls -la ../release/

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: native-libraries
path: packages/wasm_run/native/release/
retention-days: 7

- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/') || inputs.create_release
uses: softprops/action-gh-release@v1
with:
files: packages/wasm_run/native/release/*
tag_name: ${{ github.ref_name || format('v{0}', github.run_number) }}
draft: ${{ inputs.create_release || false }}
generate_release_notes: true
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[workspace]
members = ["packages/wasm_run/native"]
# wasm_run/native is the canonical location for the Rust native code
members = [
"packages/wasm_run/native",
]
exclude = [
"packages/rust_wasi_example",
"packages/dart_wit_component",
Expand Down
4 changes: 4 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ analyzer:
exclude:
- "packages/wasm_run/lib/src/bridge_generated.dart"
- "packages/wasm_run/lib/src/bridge_generated.web.dart"
- "packages/wasm_run/lib/src/rust/frb_generated.dart"
- "packages/wasm_run/lib/src/rust/frb_generated.io.dart"
- "packages/wasm_run/lib/src/rust/frb_generated.web.dart"
- "packages/wasm_run/lib/src/rust/**.freezed.dart"
#- '**.freezed.dart'
#- '**.g.dart'

Expand Down
216 changes: 216 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
#!/usr/bin/env bash
# Top-level build script for wasm_run
#
# Usage:
# ./build.sh clean - Clean all build artifacts (Rust and Dart)
# ./build.sh native - Build native libraries for all platforms
# ./build.sh native --check - Check tools needed for native builds
# ./build.sh dart - Build Dart packages (pub get + build_runner)
# ./build.sh all - Build everything

set -e

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

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'

log_info() { echo -e "${BLUE}ℹ${NC} $*"; }
log_success() { echo -e "${GREEN}✓${NC} $*"; }
log_warn() { echo -e "${YELLOW}⚠${NC} $*"; }
log_error() { echo -e "${RED}✗${NC} $*"; }

# Find all pubspec.yaml files (Dart packages)
find_dart_packages() {
find "$SCRIPT_DIR/packages" -name "pubspec.yaml" -type f 2>/dev/null | \
xargs -I{} dirname {} | sort -u
}

# Find all Cargo.toml files (Rust packages)
find_rust_packages() {
find "$SCRIPT_DIR/packages" -name "Cargo.toml" -type f 2>/dev/null | \
xargs -I{} dirname {} | sort -u
}

do_clean() {
log_info "Cleaning all build artifacts..."

# Clean top-level Rust workspace
if [[ -d "$SCRIPT_DIR/target" ]]; then
log_info "Removing top-level Rust target directory"
rm -rf "$SCRIPT_DIR/target"
fi

# Clean cross-rs target directory (separate from main target to avoid GLIBC issues)
if [[ -d "$SCRIPT_DIR/target-cross" ]]; then
log_info "Removing cross-rs target directory"
rm -rf "$SCRIPT_DIR/target-cross"
fi

# Clean native library builds
local native_script="$SCRIPT_DIR/packages/wasm_run/native/scripts/cross-build.sh"
if [[ -x "$native_script" ]]; then
log_info "Cleaning native build artifacts"
"$native_script" --clean
fi

# Clean all Rust packages
log_info "Cleaning Rust packages..."
while IFS= read -r pkg_dir; do
if [[ -d "$pkg_dir/target" ]]; then
log_info " Removing $pkg_dir/target"
rm -rf "$pkg_dir/target"
fi
if [[ -f "$pkg_dir/Cargo.lock" ]]; then
rm -f "$pkg_dir/Cargo.lock"
fi
done < <(find_rust_packages)

# Clean all Dart packages
log_info "Cleaning Dart packages..."
while IFS= read -r pkg_dir; do
# Remove build directories
for dir in build .dart_tool; do
if [[ -d "$pkg_dir/$dir" ]]; then
log_info " Removing $pkg_dir/$dir"
rm -rf "$pkg_dir/$dir"
fi
done
# Remove pubspec.lock (except in root/examples)
if [[ -f "$pkg_dir/pubspec.lock" ]]; then
rm -f "$pkg_dir/pubspec.lock"
fi
done < <(find_dart_packages)

# Clean platform-build directory
if [[ -d "$SCRIPT_DIR/platform-build" ]]; then
log_info "Removing platform-build directory"
rm -rf "$SCRIPT_DIR/platform-build"
fi

log_success "Clean complete"
}

do_native() {
log_info "Building native libraries..."

local native_script="$SCRIPT_DIR/packages/wasm_run/native/scripts/cross-build.sh"
if [[ ! -x "$native_script" ]]; then
log_error "Native build script not found: $native_script"
exit 1
fi

# Pass all arguments to native build script
# Default to --all --parallel if no arguments
if [[ $# -eq 0 ]]; then
"$native_script" --all --parallel
else
"$native_script" "$@"
fi
}

do_dart() {
log_info "Building Dart packages..."

# Check for dart/flutter
local dart_cmd="dart"
if command -v flutter &>/dev/null; then
dart_cmd="flutter"
elif ! command -v dart &>/dev/null; then
log_error "Neither dart nor flutter found in PATH"
exit 1
fi

while IFS= read -r pkg_dir; do
log_info "Building: $pkg_dir"
cd "$pkg_dir"

# Run pub get
$dart_cmd pub get || log_warn "pub get failed for $pkg_dir"

# Run build_runner if available
if grep -q "build_runner" pubspec.yaml 2>/dev/null; then
$dart_cmd run build_runner build --delete-conflicting-outputs || \
log_warn "build_runner failed for $pkg_dir"
fi

cd "$SCRIPT_DIR"
done < <(find_dart_packages)

log_success "Dart builds complete"
}

usage() {
cat << EOF
Usage: $0 <command> [options]

Commands:
clean Clean all build artifacts (Rust and Dart)
native [opts] Build native libraries (passes opts to cross-build.sh)
Default: --all --parallel
dart Build Dart packages (pub get + build_runner)
all Build everything (native + dart)
help Show this help message

Native build options (passed to cross-build.sh):
--check Check for required tools without building
--clean Remove built libraries only
--linux Build all Linux targets
--android Build all Android targets
--macos Build all macOS targets
--windows Build all Windows targets
--ios Build all iOS targets
--all Build all supported targets
--parallel Build targets in parallel
--keep-images Don't cleanup Docker images

Examples:
$0 clean # Clean everything
$0 native # Build all native targets in parallel
$0 native --check # Check native build tools
$0 native --linux --macos # Build only Linux and macOS
$0 dart # Build Dart packages
$0 all # Build everything
EOF
}

main() {
if [[ $# -eq 0 ]]; then
usage
exit 0
fi

local cmd="$1"
shift

case "$cmd" in
clean)
do_clean
;;
native)
do_native "$@"
;;
dart)
do_dart
;;
all)
do_native "$@"
do_dart
;;
help|--help|-h)
usage
;;
*)
log_error "Unknown command: $cmd"
usage
exit 1
;;
esac
}

main "$@"
3 changes: 2 additions & 1 deletion packages/dart_wit_component/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[package]
name = "dart_wit_component"
version = "0.0.1"
edition = "2021"
edition = "2024"
rust-version = "1.85"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
Expand Down
3 changes: 3 additions & 0 deletions packages/dart_wit_component/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Allow unsafe_op_in_unsafe_fn for WIT-generated bindings (Rust 2024 compatibility)
#![allow(unsafe_op_in_unsafe_fn)]

use std::path::Path;

mod function;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import 'package:wasm_wit_component/wasm_wit_component.dart';
import 'package:wasm_wit_component_example/host_wit_generation.dart';
import 'package:wasm_wit_component_example/test_utils.dart';

final _formatter = DartFormatter();
// Use current Dart version for formatting
final _formatter = DartFormatter(languageVersion: DartFormatter.latestLanguageVersion);

void witDartGeneratorTests({Future<Directory> Function()? getDirectory}) {
group('wit generator', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ publish_to: "none"
version: 1.0.0+1

environment:
sdk: ">=3.0.0 <4.0.0"
sdk: ">=3.6.0 <4.0.0"

dependencies:
wasm_run:
wasm_wit_component:
test: ^1.21.0
dart_style: ^2.3.0

dev_dependencies:
very_good_analysis: ^5.0.0

dependency_overrides:
dart_style: ^3.0.0
test: ^1.26.0
wasm_run:
path: ../../../wasm_run
wasm_wit_component:
path: ../

dev_dependencies:
very_good_analysis: ^10.0.0
Loading
Loading