|
| 1 | +#![allow(clippy::disallowed_macros)] |
| 2 | +use spacetimedb_guard::ensure_binaries_built; |
| 3 | +use spacetimedb_smoketests::{require_dotnet, workspace_root}; |
| 4 | +use std::process::Command; |
| 5 | + |
| 6 | +/// Test NativeAOT-LLVM build path for C# modules. |
| 7 | +/// Requires emscripten to be installed. |
| 8 | +/// Only runs on Windows since runtime.linux-x64.Microsoft.DotNet.ILCompiler.LLVM |
| 9 | +/// is not available on the dotnet-experimental NuGet feed. |
| 10 | +#[test] |
| 11 | +fn test_build_csharp_module_aot() { |
| 12 | + require_dotnet!(); |
| 13 | + |
| 14 | + // NativeAOT-LLVM is only available on Windows |
| 15 | + if std::env::consts::OS != "windows" { |
| 16 | + eprintln!("Skipping AOT test - NativeAOT-LLVM for .NET 8 only available on Windows"); |
| 17 | + return; |
| 18 | + } |
| 19 | + |
| 20 | + // Check for emscripten - skip if not available |
| 21 | + let emscripten_check = Command::new("emcc").arg("--version").output(); |
| 22 | + if emscripten_check.is_err() || !emscripten_check.unwrap().status.success() { |
| 23 | + eprintln!("Skipping AOT test - emscripten not available"); |
| 24 | + return; |
| 25 | + } |
| 26 | + |
| 27 | + let workspace = workspace_root(); |
| 28 | + let _cli_path = ensure_binaries_built(); |
| 29 | + |
| 30 | + // Set EXPERIMENTAL_WASM_AOT=1 for this specific build |
| 31 | + // Build sdk-test-cs with NativeAOT-LLVM |
| 32 | + let mut cmd = Command::new("dotnet"); |
| 33 | + cmd.arg("publish") |
| 34 | + .arg("-c") |
| 35 | + .arg("Release") |
| 36 | + .current_dir(workspace.join("modules/sdk-test-cs")) |
| 37 | + .env("EXPERIMENTAL_WASM_AOT", "1"); |
| 38 | + |
| 39 | + let output = cmd.output().expect("Failed to run dotnet publish"); |
| 40 | + assert!( |
| 41 | + output.status.success(), |
| 42 | + "NativeAOT-LLVM publish failed:\nstdout: {}\nstderr: {}", |
| 43 | + String::from_utf8_lossy(&output.stdout), |
| 44 | + String::from_utf8_lossy(&output.stderr) |
| 45 | + ); |
| 46 | + |
| 47 | + // Verify StdbModule.wasm was produced |
| 48 | + let wasm_path = workspace.join("modules/sdk-test-cs/bin/Release/net8.0/wasi-wasm/publish/StdbModule.wasm"); |
| 49 | + assert!(wasm_path.exists(), "StdbModule.wasm not found at {:?}", wasm_path); |
| 50 | +} |
0 commit comments