diff --git a/README.md b/README.md index 6a2e75f..e6c89ce 100644 --- a/README.md +++ b/README.md @@ -232,6 +232,18 @@ By default the project will find all wit files and execute wit-bindgen against e ``` +### Configuring location of generaged wit files + +By default the wit files are generated under the itermediate path `$(IntermediateOutputPath)wit_bindgen` which is by default at a location like `\obj\Debug\net9.0\wit_bindgen`. This means you can't really see the files and they will be ignored and not checked in to source by default (assuming you have a standard .net `.gitignore`) but intillisense will work. + +If you would like to have the files in a more discoverable place and potentially check the source files in you can configure the output location with a folder name and location of your choice, for example the following will create a folder `genererated/wit/` at the root of your project and put all the files in there. + +```xml + + generated/wit + +``` + ### Passing additional wit-bindgen args [wit-bindgen](https://github.com/bytecodealliance/wit-bindgen/tree/main) for c# has some advanced settings that can be set by using `WitBindgenAddtionalArgs` property. A non-exhustive list of example args that might be useful are: diff --git a/src/WitBindgen/build/BytecodeAlliance.Componentize.DotNet.WitBindgen.targets b/src/WitBindgen/build/BytecodeAlliance.Componentize.DotNet.WitBindgen.targets index 715b1b4..0175fe5 100644 --- a/src/WitBindgen/build/BytecodeAlliance.Componentize.DotNet.WitBindgen.targets +++ b/src/WitBindgen/build/BytecodeAlliance.Componentize.DotNet.WitBindgen.targets @@ -48,7 +48,7 @@ Condition="'$(Language)' == 'C#' AND '@(Wit)' != ''" DependsOnTargets="PrepareWasmSdks; WitCompile_GetDependencies; WitCompile_InvokeTool"> - + @@ -75,6 +75,7 @@ $(IntermediateOutputPath)wit_bindgen\ + $(WitGeneratedFilesRoot)\ diff --git a/test/WitBindgenTest/WitBindgenTest/CodeGenerationTest.cs b/test/WitBindgenTest/WitBindgenTest/CodeGenerationTest.cs index 54f16fb..df5d059 100644 --- a/test/WitBindgenTest/WitBindgenTest/CodeGenerationTest.cs +++ b/test/WitBindgenTest/WitBindgenTest/CodeGenerationTest.cs @@ -1,8 +1,3 @@ -using MyFuncsWorld; -using ProducerWorld; -using MyResultsWorld; -using MyWitResultsWorld; -using System; using Xunit; namespace WitBindgenTest; @@ -47,4 +42,10 @@ public void ShouldBeNormalWitResult() { Assert.NotNull((Func>)MyWitResultsWorldImpl.StringError); } + + [Fact] + public void CanChangeWitouputLocation() + { + Assert.NotNull((Func)MySimpleWorldImpl.GetNumber); + } } diff --git a/test/WitBindgenTest/WitBindgenTest/WitBindgenTest.csproj b/test/WitBindgenTest/WitBindgenTest/WitBindgenTest.csproj index 316dc09..663f47d 100644 --- a/test/WitBindgenTest/WitBindgenTest/WitBindgenTest.csproj +++ b/test/WitBindgenTest/WitBindgenTest/WitBindgenTest.csproj @@ -22,6 +22,7 @@ + diff --git a/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/Code.cs b/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/Code.cs new file mode 100644 index 0000000..bda8617 --- /dev/null +++ b/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/Code.cs @@ -0,0 +1,9 @@ +using MySimpleWorld; + +public class MySimpleWorldImpl : IMySimpleWorld +{ + public static int GetNumber() + { + return 123; + } +} diff --git a/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/LibraryWithCustomGeneratedFilesLocation.csproj b/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/LibraryWithCustomGeneratedFilesLocation.csproj new file mode 100644 index 0000000..083589d --- /dev/null +++ b/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/LibraryWithCustomGeneratedFilesLocation.csproj @@ -0,0 +1,21 @@ + + + + + + net9.0 + enable + enable + generated/wit + + + + + + + + + + + + diff --git a/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/generated/wit/MySimple.cs b/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/generated/wit/MySimple.cs new file mode 100644 index 0000000..23adb25 --- /dev/null +++ b/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/generated/wit/MySimple.cs @@ -0,0 +1,89 @@ +// Generated by `wit-bindgen` 0.40.0. DO NOT EDIT! +// +#nullable enable +using System.Runtime.InteropServices; +namespace MySimpleWorld { + + public interface IMySimpleWorld { + static abstract int GetNumber(); + + } + + public readonly struct None {} + + [StructLayout(LayoutKind.Sequential)] + public readonly struct Result + { + public readonly byte Tag; + private readonly object value; + + private Result(byte tag, object value) + { + Tag = tag; + this.value = value; + } + + public static Result Ok(TOk ok) + { + return new Result(Tags.Ok, ok!); + } + + public static Result Err(TErr err) + { + return new Result(Tags.Err, err!); + } + + public bool IsOk => Tag == Tags.Ok; + public bool IsErr => Tag == Tags.Err; + + public TOk AsOk + { + get + { + if (Tag == Tags.Ok) + { + return (TOk)value; + } + + throw new ArgumentException("expected k, got " + Tag); + } + } + + public TErr AsErr + { + get + { + if (Tag == Tags.Err) + { + return (TErr)value; + } + + throw new ArgumentException("expected Err, got " + Tag); + } + } + + public class Tags + { + public const byte Ok = 0; + public const byte Err = 1; + } + } + + namespace exports { + using System.Runtime.InteropServices; + public static class MySimpleWorld + { + + [UnmanagedCallersOnly(EntryPoint = "get-number")] + public static unsafe int wasmExportGetNumber() { + + int ret; + ret = MySimpleWorldImpl.GetNumber(); + return ret; + + } + + } + } + +} diff --git a/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/generated/wit/MySimpleWorld_component_type.wit b/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/generated/wit/MySimpleWorld_component_type.wit new file mode 100644 index 0000000..901fcca --- /dev/null +++ b/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/generated/wit/MySimpleWorld_component_type.wit @@ -0,0 +1,5 @@ +package test:simple; + +world my-simple { + export get-number: func() -> s32; +} diff --git a/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/generated/wit/MySimpleWorld_wasm_import_linkage_attribute.cs b/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/generated/wit/MySimpleWorld_wasm_import_linkage_attribute.cs new file mode 100644 index 0000000..a376f1c --- /dev/null +++ b/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/generated/wit/MySimpleWorld_wasm_import_linkage_attribute.cs @@ -0,0 +1,11 @@ +// Generated by `wit-bindgen` 0.40.0. DO NOT EDIT! +// +#nullable enable + +#if !NET9_0_OR_GREATER +// temporarily add this attribute until it is available in dotnet 9 +namespace System.Runtime.InteropServices +{ + internal partial class WasmImportLinkageAttribute : Attribute {} +} +#endif diff --git a/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/generated/wit/lastbuild.txt b/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/generated/wit/lastbuild.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/simple.wit b/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/simple.wit new file mode 100644 index 0000000..901fcca --- /dev/null +++ b/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/simple.wit @@ -0,0 +1,5 @@ +package test:simple; + +world my-simple { + export get-number: func() -> s32; +} diff --git a/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/wit-bindgen-generatedlastbuild.txt b/test/WitBindgenTest/testapps/LibraryWithCustomGeneratedFilesLocation/wit-bindgen-generatedlastbuild.txt new file mode 100644 index 0000000..e69de29