Skip to content

Commit

Permalink
add back Bytecode files
Browse files Browse the repository at this point in the history
  • Loading branch information
yowl committed Sep 4, 2024
1 parent eb3381c commit 28db215
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project>
<PropertyGroup>
<PublishTrimmed>true</PublishTrimmed>
<UseAppHost>false</UseAppHost>
<MSBuildEnableWorkloadResolver>false</MSBuildEnableWorkloadResolver>

<WasmToolsTarget Condition="$([MSBuild]::IsOSPlatform('Windows'))">win</WasmToolsTarget>
<WasmToolsTarget Condition="$([MSBuild]::IsOSPlatform('Linux'))">linux</WasmToolsTarget>
<WasmToolsTarget Condition="$([MSBuild]::IsOSPlatform('OSX'))">osx</WasmToolsTarget>
<WasmToolsTarget>$(WasmToolsTarget)-$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower())</WasmToolsTarget>
<WasmToolsExe>$(MSBuildThisFileDirectory)..\tools\$(WasmToolsTarget)\wasm-tools</WasmToolsExe>
<WasmToolsExe Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(WasmToolsExe).exe</WasmToolsExe>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<Target Name="EmitWasmOnBuild" AfterTargets="CopyFilesToOutputDirectory" DependsOnTargets="LinkNativeLlvm;"
Condition="'$(RuntimeIdentifier)' == 'wasi-wasm'">
<Message Importance="high" Text="Emit on build $(ProjectName) " />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project>
<PropertyGroup>
<WitBindgenToolTarget Condition="$([MSBuild]::IsOSPlatform('Windows'))">win</WitBindgenToolTarget>
<WitBindgenToolTarget Condition="$([MSBuild]::IsOSPlatform('Linux'))">linux</WitBindgenToolTarget>
<WitBindgenToolTarget Condition="$([MSBuild]::IsOSPlatform('OSX'))">osx</WitBindgenToolTarget>
<WitBindgenToolTarget>$(WitBindgenToolTarget)-$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower())</WitBindgenToolTarget>
<WitBindgenExe>$(MSBuildThisFileDirectory)..\tools\$(WitBindgenToolTarget)\wit-bindgen</WitBindgenExe>
<WitBindgenExe Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(WitBindgenExe).exe</WitBindgenExe>
<WkgExe>$(MSBuildThisFileDirectory)..\tools\$(WitBindgenToolTarget)\wkg</WkgExe>
<WkgExe Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(WkgExe).exe</WkgExe>

<!-- We have to add this to the application's project because the codegen uses unsafe in marshalling -->
<!-- An alternative would be to emit code that uses some kind of Wit.Runtime project that deals with the unsafe aspects -->
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemDefinitionGroup>
<Wit>
<!-- On save, trigger a design-time build -->
<Generator>MSBuild:Compile</Generator>
</Wit>
</ItemDefinitionGroup>

<ItemGroup Condition="'$(Language)' == 'C#'">
<PropertyPageSchema Include="$(MSBuildThisFileDirectory)Wit.CSharp.xml">
<Context>File;BrowseObject</Context>
</PropertyPageSchema>

<Wit Include="*.wit;wit/*.wit" />

<!-- Treats this itemgroup as a compilation input (e.g., changes affect VS fast up-to-date check, and generator is shown in properties pane) -->
<AvailableItemName Include="Wit" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<Project>
<PropertyGroup>
<WitBindgenRuntime>native-aot</WitBindgenRuntime>

<!-- Keep this block all in sync manually, since URLs can be arbitrary -->
<WasiSdkVersion>24.0</WasiSdkVersion>
<WasiSdkUrl Condition="$([MSBuild]::IsOSPlatform('Windows'))">https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$(WasiSdkVersion.Split(".")[0])/wasi-sdk-$(WasiSdkVersion)-x86_64-windows.tar.gz</WasiSdkUrl>
<WasiSdkUrl Condition="$([MSBuild]::IsOSPlatform('Linux'))">https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$(WasiSdkVersion.Split(".")[0])/wasi-sdk-$(WasiSdkVersion)-x86_64-linux.tar.gz</WasiSdkUrl>
<WasiSdkUrl Condition="$([MSBuild]::IsOSPlatform('OSX'))">https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$(WasiSdkVersion.Split(".")[0])/wasi-sdk-$(WasiSdkVersion)-x86_64-macos.tar.gz</WasiSdkUrl>
<WasiSdkRoot>$([System.IO.Path]::Combine("$([System.Environment]::GetFolderPath(SpecialFolder.UserProfile))", ".wasi-sdk", "wasi-sdk-$(WasiSdkVersion)"))</WasiSdkRoot>

</PropertyGroup>

<!--
MSBuild stuff to acquire the necessary SDKs (WASI SDK) automatically. It will take a few mins on the
first build on a given machine, but after that should no-op.
-->
<Target Name="PrepareWasmSdks" BeforeTargets="CheckWasmSdks" DependsOnTargets="ObtainWasiSdk">
<PropertyGroup>
<WASI_SDK_PATH>$(WasiSdkRoot)</WASI_SDK_PATH>
</PropertyGroup>
</Target>

<Target Name="ObtainWasiSdk" Condition="!(Exists($(WasiSdkRoot)))">
<PropertyGroup>
<WasiSdkDownloadTempDir>$([System.IO.Path]::Combine($([System.IO.Path]::GetTempPath()), $([System.IO.Path]::GetRandomFileName())))</WasiSdkDownloadTempDir>
</PropertyGroup>

<MakeDir Directories="$(WasiSdkDownloadTempDir)" />
<DownloadFile
SourceUrl="$(WasiSdkUrl)"
DestinationFolder="$(WasiSdkDownloadTempDir)">
<Output TaskParameter="DownloadedFile" ItemName="WasiSdkDownloadTempFile" />
</DownloadFile>

<!-- Windows 10+ has tar built in, so this should work cross-platform -->
<Message Importance="high" Text="Extracting @(WasiSdkDownloadTempFile) to $(WasiSdkRoot)..." />
<MakeDir Directories="$(WasiSdkRoot)" />
<Exec Command="tar -xf &quot;@(WasiSdkDownloadTempFile)&quot; -C . --strip-components=1" WorkingDirectory="$(WasiSdkRoot)" />
<RemoveDir Directories="$(WasiSdkDownloadTempDir)" />
</Target>

<!--
Following generats and compiles the wit code for the c# project
-->
<Target Name="WitCompile_BeforeCsCompile" BeforeTargets="LinkNativeLlvm; BeforeCompile; "
Condition="'$(Language)' == 'C#' AND '@(Wit)' != ''"
DependsOnTargets="PrepareWasmSdks; WitCompile_GetDependencies; WitCompile_InvokeTool">
<ItemGroup>
<Compile Include="$(WitGeneratedFilesRoot)**\*.cs" />
</ItemGroup>
</Target>

<Target Name="PullWitOciFiles" Inputs="@(Wit)" Outputs="@(Wit)" BeforeTargets="WitCompile_InvokeTool">
<PropertyGroup>
<WitOciFile>@(Wit)</WitOciFile>
</PropertyGroup>
<Message Condition="'%(Wit.Registry)' != ''" Importance="high" Text="Pulling OCI %(Wit.Registry) to %(Wit.RelativeDir)..." />
<MakeDir Condition="'%(Wit.Registry)' != '' AND !Exists('%(Wit.RelativeDir)')" Directories="%(Wit.RelativeDir)" />
<Exec Condition="'%(Wit.Registry)' != ''" Command="$(WkgExe) oci pull %(Wit.Registry) --output $(WitOciFile)" />
</Target>

<Target Name="WitCompile_GetDependencies" DependsOnTargets="WitCompile_InvokeTool">

<ItemGroup>
<WitGeneratedCsFiles Include="$(WitGeneratedFilesRoot)**\*.cs" />
<WitComponentImports Include="$(WitGeneratedFilesRoot)**\*.wit"/>
</ItemGroup>
<ItemGroup>
<CustomLinkerArg Include="@(WitComponentImports->Replace('\', '/')->'-Wl,--component-type,&quot;%(Identity)&quot;')" />
</ItemGroup>
</Target>

<Target Name="WitCompile_InvokeTool" Inputs="@(Wit);$(MSBuildProjectFile)" Outputs="@(WitGeneratedCsFiles);$(WitGeneratedFilesRoot)lastbuild.txt">
<PropertyGroup>
<WitGeneratedFilesRoot Condition="'$(WitGeneratedFilesRoot)' == ''">$(IntermediateOutputPath)wit_bindgen\</WitGeneratedFilesRoot>
</PropertyGroup>
<ItemGroup>
<WitGeneratedCsFiles Remove="@(WitGeneratedCsFiles)" />
<Wit Update="@(Wit)">
<WitWorldArg Condition="'%(Wit.World)' != ''">--world %(Wit.World)</WitWorldArg>
</Wit>
</ItemGroup>

<Message Importance="high" Text="Executing wit-bindgen..." />

<RemoveDir Directories="$(WitGeneratedFilesRoot)" />
<MakeDir Directories="$(WitGeneratedFilesRoot)" />
<Exec Command="$(WitBindgenExe) c-sharp %(Wit.Identity) %(Wit.WitWorldArg) --runtime $(WitBindgenRuntime) --out-dir $(WitGeneratedFilesRoot)" />
<WriteLinesToFile File="$(WitGeneratedFilesRoot)lastbuild.txt" Lines="" Overwrite="true" />

<ItemGroup>
<WitGeneratedCsFiles Include="$(WitGeneratedFilesRoot)**\*.cs" />
<FileWrites Include="$(WitGeneratedFilesRoot)lastbuild.txt" />
<FileWrites Include="$(WitGeneratedFilesRoot)**" />
</ItemGroup>
</Target>
</Project>

0 comments on commit 28db215

Please sign in to comment.