diff options
author | Christian Scheuer <info@creatix.dk> | 2018-02-04 03:47:18 +0300 |
---|---|---|
committer | Morgan Brown <morganbr@users.noreply.github.com> | 2018-02-04 03:47:18 +0300 |
commit | f19daaae780f2b0b2675792a8b0ef071dc1e58ff (patch) | |
tree | 638ec60b9f3f2c538b9288a1f8ab32f8dc8f0048 | |
parent | 2aaccdfc08dc2217bbc1777d4c98dda2a4867fb7 (diff) |
Add support for building wasm on OSX and Ubuntu 16 (#5297)
* Enable wasm building on OSX.
Upgrade libLLVM to 4.0.0 and LLVMSharp to 5.0.0
LLVM upgrade: Fix 'Use still stuck around after Def is destroyed' of the deleted basic blocks
Add wasm support in runtest.sh
Remove HelloWasm.csproj reference to .ilproj on non-windows OS because of dependency on ilasm
Fix LinkNative target to execute correct commands for Unix wasm builds.
Added support for building on Ubuntu 16.04.3
Update documentation on how to build WebAssembly.
-rw-r--r-- | Documentation/how-to-build-WebAssembly.md | 29 | ||||
-rw-r--r-- | buildscripts/buildvars-setup.cmd | 1 | ||||
-rwxr-xr-x | buildscripts/buildvars-setup.sh | 69 | ||||
-rw-r--r-- | dir.props | 1 | ||||
-rw-r--r-- | src/BuildIntegration/Microsoft.NETCore.Native.Unix.props | 25 | ||||
-rw-r--r-- | src/BuildIntegration/Microsoft.NETCore.Native.targets | 9 | ||||
-rw-r--r-- | src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs | 5 | ||||
-rw-r--r-- | src/ILCompiler.WebAssembly/src/CodeGen/WebAssemblyObjectWriter.cs | 4 | ||||
-rw-r--r-- | src/ILCompiler.WebAssembly/src/Compiler/WebAssemblyCodegenCompilation.cs | 1 | ||||
-rw-r--r-- | src/ILCompiler.WebAssembly/src/ILCompiler.WebAssembly.csproj | 23 | ||||
-rw-r--r-- | src/ILCompiler.WebAssembly/src/libLLVMdep.depproj | 22 | ||||
-rwxr-xr-x | src/Native/gen-buildsys-clang.sh | 1 | ||||
-rwxr-xr-x | tests/runtest.sh | 47 | ||||
-rw-r--r-- | tests/src/Simple/HelloWasm/HelloWasm.csproj | 8 | ||||
-rw-r--r-- | tests/src/Simple/HelloWasm/Program.cs | 4 | ||||
-rw-r--r-- | tests/src/Simple/HelloWasm/no_unix | 1 | ||||
-rwxr-xr-x | tests/testenv.sh | 47 |
17 files changed, 202 insertions, 95 deletions
diff --git a/Documentation/how-to-build-WebAssembly.md b/Documentation/how-to-build-WebAssembly.md index 72fb034b2..84e6ed6df 100644 --- a/Documentation/how-to-build-WebAssembly.md +++ b/Documentation/how-to-build-WebAssembly.md @@ -1,5 +1,6 @@ # Build WebAssembly # -Currently, building WebAssembly is only possible on Windows. + +## Build WebAssembly on Windows ## 1. Install Emscripten by following the instructions [here](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html). 2. Follow the instructions [here](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html#updating-the-sdk) to update Emscripten to the latest version. @@ -7,15 +8,33 @@ Currently, building WebAssembly is only possible on Windows. 4. Build the WebAssembly runtime by running ```build.cmd wasm``` from the repo root. 5. Run the WebAssembly "Hello World" test by running ```C:\corert\tests\runtest.cmd wasm```. -To debug compiling WebAssembly: +## Build WebAssembly on OSX ## + +1. Install Emscripten by following the instructions [here](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html). +2. Follow the instructions [here](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html#updating-the-sdk) to update Emscripten to the latest version. +3. Get CoreRT set up by installing [Prerequisites](prerequisites-for-building.md). +4. Build the WebAssembly runtime by running ```./build.sh wasm``` from the repo root. +5. Run the WebAssembly "Hello World" test by opening it in [Firefox](https://www.getfirefox.com). + +## Build WebAssembly on Ubuntu 16.04.3 ## + +1. Get CoreRT set up by installing [Prerequisites](prerequisites-for-building.md), except install ```libicu55``` for Ubuntu 16 instead of ```libicu52```. +2. Install Emscripten by following the instructions [here](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html). +3. Follow the instructions [here](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html#updating-the-sdk) to update Emscripten to the latest version. +4. Build the WebAssembly runtime by running ```./build.sh wasm``` from the repo root. +5. Run the WebAssembly "Hello World" test by opening it in [Firefox](https://www.getfirefox.com). + + +# How to debug the IL->WebAssembly compilation # +This is Windows only for now. 1. Set the ILCompiler startup command line to ```@C:\corert\tests\src\Simple\HelloWasm\obj\Debug\wasm\native\HelloWasm.ilc.rsp```. That will generate HelloWasm.bc, an LLVM bitcode file. 2. To compile that to WebAssembly, run ```emcc HelloWasm.bc -s ALLOW_MEMORY_GROWTH=1 C:\corert\bin\WebAssembly.wasm.Debug\sdk\libPortableRuntime.bc C:\corert\bin\WebAssembly.wasm.Debug\sdk\libbootstrappercpp.bc -s WASM=1 -o HelloWasm.html``` (if emcc isn't on your path, you'll need to launch an Emscripten command prompt to do this). That will generate a .wasm file with your code as well as html and js files to run it. -To run a WebAssembly application -1. Ensure you have Edge 41 or above or [Firefox](https://www.getfirefox.com). +# How to run a WebAssembly application # +1. Ensure you have Edge 41 (Windows only) or above or [Firefox](https://www.getfirefox.com). 2. Open the generated html file in Edge or Firefox and look at the on-screen console for output. -Useful tips: +# Useful tips # * To manually make ILC compile to WebAssembly, add ```--wasm``` to the command line. * Add ```-g3``` to the emcc command line to generate more debuggable output and a .wast file with the text form of the WebAssembly. * Omit ```-s WASM=1``` from the emcc command line to generate asm.js. Browser debuggers currently work better with asm.js and it's often a bit more readable than wast. diff --git a/buildscripts/buildvars-setup.cmd b/buildscripts/buildvars-setup.cmd index 9e4f828f7..a3e0a5f1d 100644 --- a/buildscripts/buildvars-setup.cmd +++ b/buildscripts/buildvars-setup.cmd @@ -2,6 +2,7 @@ set __BuildArch=x64 set __BuildType=Debug set __BuildOS=Windows_NT +set __HostOS=Windows_NT :: Set the various build properties here so that CMake and MSBuild can pick them up set "__ProjectDir=%~dp0.." diff --git a/buildscripts/buildvars-setup.sh b/buildscripts/buildvars-setup.sh index 161556565..4b2fd8f12 100755 --- a/buildscripts/buildvars-setup.sh +++ b/buildscripts/buildvars-setup.sh @@ -193,41 +193,44 @@ done export $__BuildArch +# Use uname to determine what the OS is. +export OSName=$(uname -s) +case $OSName in + Darwin) + export __HostOS=OSX + export __NugetRuntimeId=osx.10.10-x64 + ulimit -n 2048 + ;; + + FreeBSD) + export __HostOS=FreeBSD + # TODO: Add proper FreeBSD target + export __NugetRuntimeId=ubuntu.14.04-x64 + ;; + + Linux) + export __HostOS=Linux + export __NugetRuntimeId=$(get_current_linux_rid)-$__HostArch + ;; + + NetBSD) + export __HostOS=NetBSD + # TODO: Add proper NetBSD target + export __NugetRuntimeId=ubuntu.14.04-x64 + ;; + + *) + echo "Unsupported OS $OSName detected, configuring as if for Linux" + export __HostOS=Linux + export __NugetRuntimeId=ubuntu.14.04-x64 + ;; +esac + +export __BuildOS="$__HostOS" + +# Overwrite __BuildOS with WebAssembly if wasm is target build arch, but keep the __NugetRuntimeId to match the Host OS if [ $__BuildArch == "wasm" ]; then export __BuildOS=WebAssembly -else - # Use uname to determine what the OS is. - export OSName=$(uname -s) - case $OSName in - Darwin) - export __BuildOS=OSX - export __NugetRuntimeId=osx.10.10-x64 - ulimit -n 2048 - ;; - - FreeBSD) - export __BuildOS=FreeBSD - # TODO: Add proper FreeBSD target - export __NugetRuntimeId=ubuntu.14.04-x64 - ;; - - Linux) - export __BuildOS=Linux - export __NugetRuntimeId=$(get_current_linux_rid)-$__HostArch - ;; - - NetBSD) - export __BuildOS=NetBSD - # TODO: Add proper NetBSD target - export __NugetRuntimeId=ubuntu.14.04-x64 - ;; - - *) - echo "Unsupported OS $OSName detected, configuring as if for Linux" - export __BuildOS=Linux - export __NugetRuntimeId=ubuntu.14.04-x64 - ;; - esac fi # If neither managed nor native are passed as arguments, default to building both @@ -12,6 +12,7 @@ <PropertyGroup> <OSGroup Condition="'$(OSGroup)'==''">$(__BuildOS)</OSGroup> <Platform Condition="'$(Platform)'==''">$(__BuildArch)</Platform> + <HostOS Condition="'$(HostOS)'==''">$(__HostOS)</HostOS> <Configuration Condition="'$(Configuration)'==''">$(__BuildType)</Configuration> </PropertyGroup> diff --git a/src/BuildIntegration/Microsoft.NETCore.Native.Unix.props b/src/BuildIntegration/Microsoft.NETCore.Native.Unix.props index 03be5996b..441f4754c 100644 --- a/src/BuildIntegration/Microsoft.NETCore.Native.Unix.props +++ b/src/BuildIntegration/Microsoft.NETCore.Native.Unix.props @@ -33,6 +33,11 @@ See the LICENSE file in the project root for more information. </PropertyGroup> <Target Name="SetupOSSpecificProps" DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)"> + <PropertyGroup> + <NativeLibraryExtension Condition="'$(NativeCodeGen)' != 'wasm'">.a</NativeLibraryExtension> + <NativeLibraryExtension Condition="'$(NativeCodeGen)' == 'wasm'">.bc</NativeLibraryExtension> + </PropertyGroup> + <ItemGroup> <CppCompilerAndLinkerArg Include="-I $(IlcPath)/inc" /> <CppCompilerAndLinkerArg Condition="'$(Configuration)' == 'Debug'" Include="-g -O0" /> @@ -48,19 +53,19 @@ See the LICENSE file in the project root for more information. <NativeLibrary Condition="$(NativeCodeGen) == ''" Include="$(IlcPath)/sdk/libRuntime.a" /> <NativeLibrary Condition="$(NativeCodeGen) == 'cpp'" Include="$(IlcPath)/sdk/libbootstrappercpp.a" /> <NativeLibrary Condition="$(NativeCodeGen) == 'cpp'" Include="$(IlcPath)/sdk/libPortableRuntime.a" /> - <NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)/sdk/libbootstrappercpp.a" /> - <NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)/sdk/libPortableRuntime.a" /> + <NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)/sdk/libbootstrappercpp.bc" /> + <NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)/sdk/libPortableRuntime.bc" /> </ItemGroup> <ItemGroup> - <NativeLibrary Include="$(IlcPath)/sdk/libSystem.Private.CoreLib.Native.a" /> - <NativeLibrary Include="$(IlcPath)/framework/System.Native.a" /> - <NativeLibrary Include="$(IlcPath)/framework/System.Globalization.Native.a" /> - <NativeLibrary Include="$(IlcPath)/framework/System.IO.Compression.Native.a" /> - <NativeLibrary Include="$(IlcPath)/framework/System.Net.Http.Native.a" /> - <NativeLibrary Include="$(IlcPath)/framework/System.Net.Security.Native.a" /> - <NativeLibrary Include="$(IlcPath)/framework/System.Security.Cryptography.Native.Apple.a" Condition="'$(TargetOS)' == 'OSX'"/> - <NativeLibrary Include="$(IlcPath)/framework/System.Security.Cryptography.Native.OpenSsl.a" Condition="'$(TargetOS)' != 'OSX'"/> + <NativeLibrary Include="$(IlcPath)/sdk/libSystem.Private.CoreLib.Native$(NativeLibraryExtension)" /> + <NativeLibrary Include="$(IlcPath)/framework/System.Native$(NativeLibraryExtension)" /> + <NativeLibrary Include="$(IlcPath)/framework/System.Globalization.Native$(NativeLibraryExtension)" /> + <NativeLibrary Include="$(IlcPath)/framework/System.IO.Compression.Native$(NativeLibraryExtension)" /> + <NativeLibrary Include="$(IlcPath)/framework/System.Net.Http.Native$(NativeLibraryExtension)" /> + <NativeLibrary Include="$(IlcPath)/framework/System.Net.Security.Native$(NativeLibraryExtension)" /> + <NativeLibrary Include="$(IlcPath)/framework/System.Security.Cryptography.Native.Apple$(NativeLibraryExtension)" Condition="'$(TargetOS)' == 'OSX'"/> + <NativeLibrary Include="$(IlcPath)/framework/System.Security.Cryptography.Native.OpenSsl$(NativeLibraryExtension)" Condition="'$(TargetOS)' != 'OSX'"/> </ItemGroup> <ItemGroup Condition="'$(TargetOS)' == 'OSX'"> diff --git a/src/BuildIntegration/Microsoft.NETCore.Native.targets b/src/BuildIntegration/Microsoft.NETCore.Native.targets index 1e70f4aa4..e93c1d4de 100644 --- a/src/BuildIntegration/Microsoft.NETCore.Native.targets +++ b/src/BuildIntegration/Microsoft.NETCore.Native.targets @@ -214,8 +214,8 @@ See the LICENSE file in the project root for more information. <MakeDir Directories="$([System.IO.Path]::GetDirectoryName($(NativeBinary)))" /> - <Exec Command="$(CppLinker) @(CustomLinkerArg, ' ')" Condition="'$(OS)' != 'Windows_NT' and '$(NativeLib)' != 'Static'" /> - <Exec Command="$(CppLibCreator) @(CustomLibArg, ' ')" Condition="'$(OS)' != 'Windows_NT' and '$(NativeLib)' == 'Static'" /> + <Exec Command="$(CppLinker) @(CustomLinkerArg, ' ')" Condition="'$(OS)' != 'Windows_NT' and '$(NativeLib)' != 'Static' and '$(NativeCodeGen)' != 'wasm'" /> + <Exec Command="$(CppLibCreator) @(CustomLibArg, ' ')" Condition="'$(OS)' != 'Windows_NT' and '$(NativeLib)' == 'Static' and '$(NativeCodeGen)' != 'wasm'" /> <WriteLinesToFile File="$(NativeIntermediateOutputPath)link.rsp" Lines="@(CustomLinkerArg)" Overwrite="true" Condition="'$(OS)' == 'Windows_NT' and '$(NativeLib)' != 'Static'" /> <Exec Command="$(CppLinker) @"$(NativeIntermediateOutputPath)link.rsp"" Condition="'$(OS)' == 'Windows_NT' and '$(NativeLib)' != 'Static' and '$(NativeCodeGen)' != 'wasm'" /> @@ -224,12 +224,13 @@ See the LICENSE file in the project root for more information. <PropertyGroup> <EmccArgs>"$(NativeObject)" -o "$(NativeBinary)" -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 </EmccArgs> - <EmccArgs Condition="'$(Platform)'=='wasm'">$(EmccArgs) "$(IlcPath)\sdk\libPortableRuntime.bc" "$(IlcPath)\sdk\libbootstrappercpp.bc" </EmccArgs> + <EmccArgs Condition="'$(Platform)'=='wasm'">$(EmccArgs) "$(IlcPath)/sdk/libPortableRuntime.bc" "$(IlcPath)/sdk/libbootstrappercpp.bc" </EmccArgs> <EmccArgs Condition="'$(Configuration)'=='Release'">$(EmccArgs) -O2 --llvm-lto 2</EmccArgs> <EmccArgs Condition="'$(Configuration)'=='Debug'">$(EmccArgs) -g3</EmccArgs> </PropertyGroup> - <Exec Command=""$(EMSCRIPTEN)\emcc.bat" $(EmccArgs)" Condition="'$(NativeCodeGen)' == 'wasm' and '$(EMSCRIPTEN)' != ''" /> + <Exec Command=""$(EMSCRIPTEN)\emcc.bat" $(EmccArgs)" Condition="'$(NativeCodeGen)' == 'wasm' and '$(EMSCRIPTEN)' != '' and '$(OS)' == 'Windows_NT'" /> + <Exec Command=""$(EMSCRIPTEN)/emcc" $(EmccArgs)" Condition="'$(NativeCodeGen)' == 'wasm' and '$(EMSCRIPTEN)' != '' and '$(OS)' != 'Windows_NT'" /> <Message Text="Emscripten not found, not linking WebAssembly. To enable WebAssembly linking, install Emscripten and ensure the EMSCRIPTEN environment variable points to the directory containing emcc.bat" Condition="'$(NativeCodeGen)' == 'wasm' and '$(EMSCRIPTEN)' == ''" /> </Target> diff --git a/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs b/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs index a24c1efe9..1ac1869c3 100644 --- a/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs +++ b/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs @@ -116,15 +116,18 @@ namespace Internal.IL } catch { + LLVMBasicBlockRef trapBlock = LLVM.AppendBasicBlock(_llvmFunction, "Trap"); + // Change the function body to trap foreach (BasicBlock block in _basicBlocks) { if (block != null && block.Block.Pointer != IntPtr.Zero) { + LLVM.ReplaceAllUsesWith(block.Block, trapBlock); LLVM.DeleteBasicBlock(block.Block); } } - LLVMBasicBlockRef trapBlock = LLVM.AppendBasicBlock(_llvmFunction, "Trap"); + LLVM.PositionBuilderAtEnd(_builder, trapBlock); EmitTrapCall(); LLVM.BuildRetVoid(_builder); diff --git a/src/ILCompiler.WebAssembly/src/CodeGen/WebAssemblyObjectWriter.cs b/src/ILCompiler.WebAssembly/src/CodeGen/WebAssemblyObjectWriter.cs index 9cb9b26d5..8808a2e02 100644 --- a/src/ILCompiler.WebAssembly/src/CodeGen/WebAssemblyObjectWriter.cs +++ b/src/ILCompiler.WebAssembly/src/CodeGen/WebAssemblyObjectWriter.cs @@ -183,9 +183,9 @@ namespace ILCompiler.DependencyAnalysis EmitNativeMain(); LLVM.WriteBitcodeToFile(Module, _objectFilePath); #if DEBUG - LLVM.PrintModuleToFile(Module, Path.ChangeExtension(_objectFilePath, ".txt"), out IntPtr unused2); + LLVM.PrintModuleToFile(Module, Path.ChangeExtension(_objectFilePath, ".txt"), out string unused2); #endif //DEBUG - LLVM.VerifyModule(Module, LLVMVerifierFailureAction.LLVMAbortProcessAction, out IntPtr unused); + LLVM.VerifyModule(Module, LLVMVerifierFailureAction.LLVMAbortProcessAction, out string unused); //throw new NotImplementedException(); // This function isn't complete } diff --git a/src/ILCompiler.WebAssembly/src/Compiler/WebAssemblyCodegenCompilation.cs b/src/ILCompiler.WebAssembly/src/Compiler/WebAssemblyCodegenCompilation.cs index 94b35a3f4..5a32248a7 100644 --- a/src/ILCompiler.WebAssembly/src/Compiler/WebAssemblyCodegenCompilation.cs +++ b/src/ILCompiler.WebAssembly/src/Compiler/WebAssemblyCodegenCompilation.cs @@ -26,7 +26,6 @@ namespace ILCompiler : base(dependencyGraph, nodeFactory, GetCompilationRoots(roots, nodeFactory), null, null, logger) { NodeFactory = nodeFactory; - LLVM.LoadLibrary_libLLVM("./libLLVM-x64.dll"); Module = LLVM.ModuleCreateWithName("netscripten"); LLVM.SetTarget(Module, "asmjs-unknown-emscripten"); Options = options; diff --git a/src/ILCompiler.WebAssembly/src/ILCompiler.WebAssembly.csproj b/src/ILCompiler.WebAssembly/src/ILCompiler.WebAssembly.csproj index cd88923c7..2eb7e3eeb 100644 --- a/src/ILCompiler.WebAssembly/src/ILCompiler.WebAssembly.csproj +++ b/src/ILCompiler.WebAssembly/src/ILCompiler.WebAssembly.csproj @@ -10,15 +10,18 @@ <NoWarn>8002</NoWarn> <OutputPath>$(BaseOutputPath)$(OSPlatformConfig)/tools</OutputPath> </PropertyGroup> + <ItemGroup> <PackageReference Include="LLVMSharp"> - <Version>3.9.1-rc3</Version> - </PackageReference> - <PackageReference Include="libLLVM"> - <Version>3.9.1</Version> - </PackageReference> + <Version>5.0.0</Version> + </PackageReference> </ItemGroup> + <ItemGroup Condition="'$(IsProjectNLibrary)' != 'true'"> + <ProjectReference Include="libLLVMdep.depproj"> + <ReferenceOutputAssembly>false</ReferenceOutputAssembly> + <SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties> + </ProjectReference> <ProjectReference Include="..\..\ILCompiler.DependencyAnalysisFramework\src\ILCompiler.DependencyAnalysisFramework.csproj" /> <ProjectReference Include="..\..\ILCompiler.MetadataTransform\src\ILCompiler.MetadataTransform.csproj" /> <ProjectReference Include="..\..\ILCompiler.MetadataWriter\src\ILCompiler.MetadataWriter.csproj" /> @@ -53,10 +56,16 @@ <Compile Include="CodeGen\ILToWebAssemblyImporter.cs" /> </ItemGroup> <ItemGroup> - <Content Include="..\..\..\packages\llvmsharp\3.9.1-rc3\lib\netstandard1.1\LLVMSharp.dll"> + <Content Include="..\..\..\packages\llvmsharp\5.0.0\lib\netstandard1.1\LLVMSharp.dll"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> - <Content Include="..\..\..\packages\libllvm\3.9.1\content\libLLVM-x64.dll"> + <Content Include="..\..\..\packages\libllvm\4.0.0\runtimes\osx\native\libLLVM.dylib" Condition="'$(HostOS)' == 'OSX'"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> + <Content Include="..\..\..\packages\libllvm\4.0.0\runtimes\linux-x64\native\libLLVM.so" Condition="'$(HostOS)' == 'Linux'"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> + <Content Include="..\..\..\packages\libllvm\4.0.0\runtimes\win-x64\native\libLLVM.dll" Condition="'$(HostOS)' == 'Windows_NT'"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> </ItemGroup> diff --git a/src/ILCompiler.WebAssembly/src/libLLVMdep.depproj b/src/ILCompiler.WebAssembly/src/libLLVMdep.depproj new file mode 100644 index 000000000..5e0a14f61 --- /dev/null +++ b/src/ILCompiler.WebAssembly/src/libLLVMdep.depproj @@ -0,0 +1,22 @@ +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + + <PropertyGroup> + <OutputPath>$(BaseOutputPath)$(OSPlatformConfig)/tools</OutputPath> + </PropertyGroup> + + <PropertyGroup> + <TargetFramework>netstandard1.3</TargetFramework> + <RuntimeIdentifiers>$(NuPkgRid)</RuntimeIdentifiers> + <RuntimeIdentifiers Condition="$(NuPkgRid.StartsWith('ubuntu.'))">ubuntu.14.04-x64</RuntimeIdentifiers> + <RidSpecificAssets>true</RidSpecificAssets> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="libLLVM"> + <Version>4.0.0</Version> + </PackageReference> + </ItemGroup> + + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project> diff --git a/src/Native/gen-buildsys-clang.sh b/src/Native/gen-buildsys-clang.sh index 0c2441f77..fed57d122 100755 --- a/src/Native/gen-buildsys-clang.sh +++ b/src/Native/gen-buildsys-clang.sh @@ -117,6 +117,7 @@ if [ $build_arch == "wasm" ]; then emcmake cmake \ "-DEMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES=1" \ "-DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake" \ + "-DCLR_CMAKE_TARGET_ARCH=$build_arch" \ "-DCMAKE_BUILD_TYPE=$build_type" \ "$1/src/Native" else diff --git a/tests/runtest.sh b/tests/runtest.sh index 15bff4f2e..36d087023 100755 --- a/tests/runtest.sh +++ b/tests/runtest.sh @@ -41,6 +41,9 @@ run_test_dir() if [ "${__mode}" = "Cpp" ]; then __extra_args="${__extra_args} /p:NativeCodeGen=cpp" fi + if [ "${__mode}" = "Wasm" ]; then + __extra_args="${__extra_args} /p:NativeCodeGen=wasm" + fi if [ -n "${__extra_cxxflags}" ]; then __extra_cxxflags="/p:AdditionalCppCompilerFlags=\"${__extra_cxxflags}\"" fi @@ -176,6 +179,12 @@ while [ "$1" != "" ]; do usage exit 1 ;; + wasm) + CoreRT_BuildArch=wasm + CoreRT_BuildOS=WebAssembly + CoreRT_TestCompileMode=wasm + CoreRT_TestRun=false + ;; x86) CoreRT_BuildArch=x86 ;; @@ -319,7 +328,8 @@ __CppTotalTests=0 __CppPassedTests=0 __JitTotalTests=0 __JitPassedTests=0 - +__WasmTotalTests=0 +__WasmPassedTests=0 if [ ! -d ${__CoreRTTestBinDir} ]; then mkdir -p ${__CoreRTTestBinDir} @@ -330,20 +340,28 @@ __BuildOsLowcase=$(echo "${CoreRT_BuildOS}" | tr '[:upper:]' '[:lower:]') __TestSearchPath=${CoreRT_TestRoot}/src/Simple/${CoreRT_TestName} for csproj in $(find ${__TestSearchPath} -name "*.csproj") do - if [ ! -e `dirname ${csproj}`/no_unix ]; then - if [ "${CoreRT_TestCompileMode}" != "cpp" ]; then + if [ -e `dirname ${csproj}`/no_unix ]; then continue; fi + if [ -e `dirname ${csproj}`/no_linux ] && [ "${CoreRT_HostOS}" != "OSX" ]; then continue; fi + + if [ "${CoreRT_TestCompileMode}" = "ryujit" ] || [ "${CoreRT_TestCompileMode}" = "" ]; then + if [ ! -e `dirname ${csproj}`/no_ryujit ]; then run_test_dir ${csproj} "Jit" fi + fi + if [ "${CoreRT_TestCompileMode}" = "cpp" ] || [ "${CoreRT_TestCompileMode}" = "" ]; then if [ ! -e `dirname ${csproj}`/no_cpp ]; then - if [ "${CoreRT_TestCompileMode}" != "ryujit" ]; then - run_test_dir ${csproj} "Cpp" "$CoreRT_ExtraCXXFlags" "$CoreRT_ExtraLinkFlags" - fi + run_test_dir ${csproj} "Cpp" "$CoreRT_ExtraCXXFlags" "$CoreRT_ExtraLinkFlags" + fi + fi + if [ "${CoreRT_TestCompileMode}" = "wasm" ]; then + if [ -e `dirname ${csproj}`/wasm ]; then + run_test_dir ${csproj} "Wasm" fi fi done -__TotalTests=$((${__JitTotalTests} + ${__CppTotalTests})) -__PassedTests=$((${__JitPassedTests} + ${__CppPassedTests})) +__TotalTests=$((${__JitTotalTests} + ${__CppTotalTests} + ${__WasmTotalTests})) +__PassedTests=$((${__JitPassedTests} + ${__CppPassedTests} + ${__WasmPassedTests})) __FailedTests=$((${__TotalTests} - ${__PassedTests})) if [ "$CoreRT_MultiFileConfiguration" = "MultiModule" ]; then @@ -366,19 +384,26 @@ echo "</assemblies>" >> ${__TestResultsLog} echo "JIT - TOTAL: ${__JitTotalTests} PASSED: ${__JitPassedTests}" echo "CPP - TOTAL: ${__CppTotalTests} PASSED: ${__CppPassedTests}" +echo "WASM - TOTAL: ${__WasmTotalTests} PASSED: ${__WasmPassedTests}" -if [ ${__JitTotalTests} == 0 ]; then +if [ ${__JitTotalTests} == 0 ] && [ "${CoreRT_TestCompileMode}" != "wasm" ]; then exit 1 fi - -if [ ${__CppTotalTests} == 0 ]; then +if [ ${__CppTotalTests} == 0 ] && [ "${CoreRT_TestCompileMode}" != "wasm" ]; then exit 1 fi +if [ ${__WasmTotalTests} == 0 ] && [ "${CoreRT_TestCompileMode}" = "wasm" ]; then + exit 1 +fi + if [ ${__JitTotalTests} -gt ${__JitPassedTests} ]; then exit 1 fi if [ ${__CppTotalTests} -gt ${__CppPassedTests} ]; then exit 1 fi +if [ ${__WasmTotalTests} -gt ${__WasmPassedTests} ]; then + exit 1 +fi exit 0 diff --git a/tests/src/Simple/HelloWasm/HelloWasm.csproj b/tests/src/Simple/HelloWasm/HelloWasm.csproj index b767a5dbd..f070f287a 100644 --- a/tests/src/Simple/HelloWasm/HelloWasm.csproj +++ b/tests/src/Simple/HelloWasm/HelloWasm.csproj @@ -2,9 +2,13 @@ <ItemGroup> <Compile Include="*.cs" /> - <ProjectReference Include="CpObj.ilproj" /> - <IlcArg Include="-r:$(IntermediateOutputPath)\CpObj.dll" /> + <ProjectReference Include="CpObj.ilproj" Condition="'$(OS)' == 'Windows_NT'" /> + <IlcArg Include="-r:$(IntermediateOutputPath)\CpObj.dll" Condition="'$(OS)' == 'Windows_NT'" /> </ItemGroup> + <PropertyGroup Condition="'$(OS)' == 'Windows_NT'"> + <DefineConstants>PLATFORM_WINDOWS;$(DefineConstants)</DefineConstants> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), SimpleTest.targets))\SimpleTest.targets" /> </Project> diff --git a/tests/src/Simple/HelloWasm/Program.cs b/tests/src/Simple/HelloWasm/Program.cs index 2800c7579..bb8962c12 100644 --- a/tests/src/Simple/HelloWasm/Program.cs +++ b/tests/src/Simple/HelloWasm/Program.cs @@ -4,7 +4,9 @@ using System; using System.Runtime.InteropServices; +#if PLATFORM_WINDOWS using CpObj; +#endif internal static class Program { @@ -122,6 +124,7 @@ internal static class Program PrintLine("SwitchOpDefault test: Ok."); } +#if PLATFORM_WINDOWS var cpObjTestA = new TestValue { Field = 1234 }; var cpObjTestB = new TestValue { Field = 5678 }; CpObjTest.CpObj(ref cpObjTestB, ref cpObjTestA); @@ -129,6 +132,7 @@ internal static class Program { PrintLine("CpObj test: Ok."); } +#endif Func<int> staticDelegate = StaticDelegateTarget; if(staticDelegate() == 7) diff --git a/tests/src/Simple/HelloWasm/no_unix b/tests/src/Simple/HelloWasm/no_unix deleted file mode 100644 index e6c22996c..000000000 --- a/tests/src/Simple/HelloWasm/no_unix +++ /dev/null @@ -1 +0,0 @@ -Doesn't work on OSX.
\ No newline at end of file diff --git a/tests/testenv.sh b/tests/testenv.sh index 69a636bca..bdf8765ce 100755 --- a/tests/testenv.sh +++ b/tests/testenv.sh @@ -14,6 +14,9 @@ for i in "$@" usage exit 1 ;; + wasm) + CoreRT_BuildArch=wasm + ;; x86) CoreRT_BuildArch=x86 ;; @@ -47,7 +50,7 @@ for i in "$@" done if [ -z ${CoreRT_BuildArch} ]; then - echo "Set CoreRT_BuildArch to x86/x64/arm/arm64" + echo "Set CoreRT_BuildArch to x86/x64/arm/arm64/wasm" exit -1 fi @@ -56,31 +59,39 @@ if [ -z ${CoreRT_BuildType} ]; then exit -1 fi + # Use uname to determine what the OS is. -OSName=$(uname -s) +export OSName=$(uname -s) case $OSName in - Darwin) - CoreRT_BuildOS=OSX - ;; + Darwin) + export CoreRT_HostOS=OSX + ;; - FreeBSD) - CoreRT_BuildOS=FreeBSD - ;; + FreeBSD) + export CoreRT_HostOS=FreeBSD + ;; - Linux) - CoreRT_BuildOS=Linux - ;; + Linux) + export CoreRT_HostOS=Linux + ;; - NetBSD) - CoreRT_BuildOS=NetBSD - ;; + NetBSD) + export CoreRT_HostOS=NetBSD + ;; - *) - echo "Unsupported OS $OSName detected, configuring as if for Linux" - CoreRT_BuildOS=Linux - ;; + *) + echo "Unsupported OS $OSName detected, configuring as if for Linux" + export CoreRT_HostOS=Linux + ;; esac +export CoreRT_BuildOS=${CoreRT_HostOS} + +# Overwrite __BuildOS with WebAssembly if wasm is target build arch, but keep the CoreRT_HostOS to match the Host OS +if [ $__BuildArch == "wasm" ]; then + export CoreRT_BuildOS=WebAssembly +fi + export CoreRT_BuildArch export CoreRT_BuildType export CoreRT_BuildOS |