@@ -21,6 +21,7 @@ fn main() -> Result<()> {
2121 . with_context ( || format ! ( "Build checks failed for {template}" ) ) ?;
2222 }
2323 check_test_references ( work, & version) . context ( "Test-project reference checks failed" ) ?;
24+ check_library_reference ( work, & cli, & version) . context ( "Library project reference check failed" ) ?;
2425 check_net8 ( work, & cli) . context ( ".NET 8 WASM build check failed" ) ?;
2526 Ok ( ( ) )
2627}
@@ -326,6 +327,84 @@ public class ModuleReferenceTests
326327 Ok ( ( ) )
327328}
328329
330+ fn check_library_reference ( work : & Path , cli : & Path , version : & str ) -> Result < ( ) > {
331+ // The SDK builds a plain library reference without the module's wasi-wasm RID.
332+ // It must still compile its generated code for the WASM Runtime the module links.
333+ println ! ( "Checking a WASM module with a library project reference" ) ;
334+ let module = work. join ( "library/module" ) ;
335+ let library = module. join ( "libraries/AuthLib" ) ;
336+ fs:: create_dir_all ( & library) ?;
337+ let mut project = Element :: parse ( File :: open ( work. join ( "basic-cs/module/StdbModule.csproj" ) ) ?) ?;
338+ let references = Element :: parse (
339+ r#"<ItemGroup>
340+ <ProjectReference Include="libraries/AuthLib/AuthLib.csproj" />
341+ <Compile Remove="libraries/**/*.cs" />
342+ </ItemGroup>"#
343+ . as_bytes ( ) ,
344+ ) ?;
345+ project. children . push ( XMLNode :: Element ( references) ) ;
346+ project. write ( File :: create ( module. join ( "StdbModule.csproj" ) ) ?) ?;
347+ fs:: copy ( work. join ( "basic-cs/global.json" ) , work. join ( "library/global.json" ) ) ?;
348+ fs:: write (
349+ module. join ( "Lib.cs" ) ,
350+ r#"using SpacetimeDB;
351+
352+ [assembly: Namespace(typeof(AuthLib.Marker), Accessor = "MyAuth", Name = "auth_data")]
353+
354+ public static partial class Module
355+ {
356+ [Reducer]
357+ public static void AddAuthUser(ReducerContext ctx, uint id) => AuthLib.Functions.Add(ctx.As.MyAuth, id);
358+ }
359+ "# ,
360+ ) ?;
361+ fs:: write (
362+ library. join ( "AuthLib.csproj" ) ,
363+ format ! (
364+ r#"<Project Sdk="Microsoft.NET.Sdk">
365+ <PropertyGroup>
366+ <TargetFramework>net10.0</TargetFramework>
367+ <ImplicitUsings>enable</ImplicitUsings>
368+ <Nullable>enable</Nullable>
369+ </PropertyGroup>
370+ <ItemGroup>
371+ <PackageReference Include="SpacetimeDB.Runtime" Version="{version}" />
372+ </ItemGroup>
373+ </Project>
374+ "#
375+ ) ,
376+ ) ?;
377+ fs:: write (
378+ library. join ( "Lib.cs" ) ,
379+ r#"using SpacetimeDB;
380+
381+ // This check only builds the library as part of the WASM module.
382+ #if !SPACETIMEDB_WASM_AOT
383+ #error The library was compiled for the managed Runtime, but the module links the WASM Runtime.
384+ #endif
385+
386+ namespace AuthLib;
387+
388+ public class Marker { }
389+
390+ [Table(Accessor = "User", Name = "auth_users", Public = true)]
391+ public partial struct User
392+ {
393+ [PrimaryKey]
394+ public uint Id;
395+ }
396+
397+ public static partial class Functions
398+ {
399+ [Reducer]
400+ public static void Add(ReducerContext ctx, uint id) => ctx.Db.User.Insert(new User { Id = id });
401+ }
402+ "# ,
403+ ) ?;
404+ run ( work, cmd ! ( cli, "build" , "--module-path" , & module) ) ?;
405+ Ok ( ( ) )
406+ }
407+
329408fn check_net8 ( work : & Path , cli : & Path ) -> Result < ( ) > {
330409 // Exercise the .NET 8 SDK's WASI import order, not just our final property values.
331410 let module = work. join ( "net8/module" ) ;
0 commit comments