Skip to content

Commit f08d13f

Browse files
pavelsavararadicalakoeplinger
authored
[wasi] compile with libs.native (#79046)
* setup compilation of libs.native and mono for WASI platform * provision SDK and wasmtime * feedback Co-authored-by: Ankit Jain <[email protected]> Co-authored-by: Alexander Köplinger <[email protected]>
1 parent 58614a0 commit f08d13f

File tree

101 files changed

+2876
-794
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+2876
-794
lines changed

Directory.Build.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and '$(_hostArch)' == 's390x'">s390x</TargetArchitecture>
3737
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and '$(_hostArch)' == 'ppc64le'">ppc64le</TargetArchitecture>
3838
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and ('$(TargetOS)' == 'Browser' or '$(RuntimeIdentifier)' == 'browser-wasm')">wasm</TargetArchitecture>
39+
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and ('$(TargetOS)' == 'wasi' or '$(RuntimeIdentifier)' == 'wasi-wasm')">wasm</TargetArchitecture>
3940
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and '$(TargetsMobile)' == 'true'">x64</TargetArchitecture>
4041
<TargetArchitecture Condition="'$(TargetArchitecture)' == ''">x64</TargetArchitecture>
4142
<Platform Condition="'$(Platform)' == '' and '$(InferPlatformFromTargetArchitecture)' == 'true'">$(TargetArchitecture)</Platform>
@@ -129,6 +130,8 @@
129130
<TestExclusionListTasksAssemblyPath>$([MSBuild]::NormalizePath('$(TestExclusionListTasksDir)', 'TestExclusionListTasks.dll'))</TestExclusionListTasksAssemblyPath>
130131
<CoreCLRToolPath>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'coreclr', '$(TargetOS).$(TargetArchitecture).$(Configuration)'))</CoreCLRToolPath>
131132
<ILAsmToolPath Condition="'$(DotNetBuildFromSource)' == 'true' or '$(BuildArchitecture)' == 's390x' or '$(BuildArchitecture)' == 'ppc64le'">$(CoreCLRToolPath)</ILAsmToolPath>
133+
134+
<WasmtimeDir>$([MSBuild]::NormalizeDirectory($(ArtifactsObjDir), 'wasmtime'))</WasmtimeDir>
132135
</PropertyGroup>
133136

134137
<PropertyGroup Label="CalculateConfiguration">

eng/build.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ if ($PSBoundParameters.ContainsKey('os') -and $PSBoundParameters['os'] -eq "Brow
241241
# make sure it is capitalized
242242
$PSBoundParameters['os'] = "Browser"
243243
}
244+
if ($PSBoundParameters.ContainsKey('os') -and $PSBoundParameters['os'] -eq "wasi") {
245+
# make sure it is not capitalized
246+
$PSBoundParameters['os'] = "wasi"
247+
}
244248

245249
foreach ($argument in $PSBoundParameters.Keys)
246250
{

eng/native/configurecompiler.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ elseif (CLR_CMAKE_HOST_UNIX)
168168
endif ()
169169
endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL CHECKED)
170170

171-
if(CLR_CMAKE_HOST_BROWSER)
171+
if(CLR_CMAKE_HOST_BROWSER OR CLR_CMAKE_HOST_WASI)
172172
# The emscripten build has additional warnings so -Werror breaks
173173
add_compile_options(-Wno-unused-parameter)
174174
add_compile_options(-Wno-alloca)
@@ -390,7 +390,7 @@ if (CLR_CMAKE_HOST_UNIX)
390390
add_definitions(-DLSE_INSTRUCTIONS_ENABLED_BY_DEFAULT)
391391
add_compile_options(-mcpu=apple-m1)
392392
endif(CLR_CMAKE_HOST_UNIX_ARM64)
393-
elseif(NOT CLR_CMAKE_HOST_BROWSER)
393+
elseif(NOT CLR_CMAKE_HOST_BROWSER AND NOT CLR_CMAKE_HOST_WASI)
394394
check_c_compiler_flag(-fstack-protector-strong COMPILER_SUPPORTS_F_STACK_PROTECTOR_STRONG)
395395
if (COMPILER_SUPPORTS_F_STACK_PROTECTOR_STRONG)
396396
add_compile_options(-fstack-protector-strong)
@@ -795,7 +795,7 @@ if (CLR_CMAKE_HOST_WIN32)
795795
message(FATAL_ERROR "MC not found")
796796
endif()
797797

798-
elseif (NOT CLR_CMAKE_HOST_BROWSER)
798+
elseif (NOT CLR_CMAKE_HOST_BROWSER AND NOT CLR_CMAKE_HOST_WASI)
799799
# This is a workaround for upstream issue: https://gitlab.kitware.com/cmake/cmake/-/issues/22995.
800800
#
801801
# In Clang.cmake, the decision to use single or double hyphen for target and gcc-toolchain

eng/native/configureplatform.cmake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ if(CLR_CMAKE_HOST_OS STREQUAL Emscripten)
214214
set(CLR_CMAKE_HOST_BROWSER 1)
215215
endif(CLR_CMAKE_HOST_OS STREQUAL Emscripten)
216216

217-
if(CLR_CMAKE_TARGET_OS STREQUAL Wasi)
217+
if(CLR_CMAKE_TARGET_OS STREQUAL WASI)
218218
set(CLR_CMAKE_HOST_WASI 1)
219-
endif(CLR_CMAKE_TARGET_OS STREQUAL Wasi)
219+
endif(CLR_CMAKE_TARGET_OS STREQUAL WASI)
220220

221221
#--------------------------------------------
222222
# This repo builds two set of binaries
@@ -417,9 +417,9 @@ if(CLR_CMAKE_TARGET_OS STREQUAL Emscripten)
417417
set(CLR_CMAKE_TARGET_BROWSER 1)
418418
endif(CLR_CMAKE_TARGET_OS STREQUAL Emscripten)
419419

420-
if(CLR_CMAKE_TARGET_OS STREQUAL Wasi)
420+
if(CLR_CMAKE_TARGET_OS STREQUAL WASI)
421421
set(CLR_CMAKE_TARGET_WASI 1)
422-
endif(CLR_CMAKE_TARGET_OS STREQUAL Wasi)
422+
endif(CLR_CMAKE_TARGET_OS STREQUAL WASI)
423423

424424
if(CLR_CMAKE_TARGET_UNIX)
425425
if(CLR_CMAKE_TARGET_ARCH STREQUAL x64)
@@ -454,7 +454,7 @@ else()
454454
endif(CLR_CMAKE_TARGET_UNIX)
455455

456456
# check if host & target os/arch combination are valid
457-
if (NOT (CLR_CMAKE_TARGET_OS STREQUAL CLR_CMAKE_HOST_OS))
457+
if (NOT (CLR_CMAKE_TARGET_OS STREQUAL CLR_CMAKE_HOST_OS) AND NOT CLR_CMAKE_TARGET_WASI)
458458
if(NOT (CLR_CMAKE_HOST_OS STREQUAL windows))
459459
message(FATAL_ERROR "Invalid host and target os/arch combination. Host OS: ${CLR_CMAKE_HOST_OS}")
460460
endif()
@@ -466,7 +466,7 @@ if (NOT (CLR_CMAKE_TARGET_OS STREQUAL CLR_CMAKE_HOST_OS))
466466
endif()
467467
endif()
468468

469-
if(NOT CLR_CMAKE_TARGET_BROWSER)
469+
if(NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI)
470470
# The default linker on Solaris also does not support PIE.
471471
if(NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_SUNOS AND NOT CLR_CMAKE_TARGET_OSX AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_HOST_TVOS AND NOT CLR_CMAKE_HOST_IOS AND NOT MSVC)
472472
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")

eng/native/configuretools.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if (CMAKE_C_COMPILER MATCHES "-?[0-9]+(\.[0-9]+)?$")
66
set(CLR_CMAKE_COMPILER_FILE_NAME_VERSION "${CMAKE_MATCH_0}")
77
endif()
88

9-
if(NOT WIN32 AND NOT CLR_CMAKE_TARGET_BROWSER)
9+
if(NOT WIN32 AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI)
1010
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
1111
if(APPLE)
1212
set(TOOLSET_PREFIX "")

eng/native/gen-buildsys.cmd

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,34 @@ if /i "%__Arch%" == "wasm" (
4848
)
4949
if /i "%__Os%" == "Browser" (
5050
if "%EMSDK_PATH%" == "" (
51-
if not exist "%__repoRoot%src\mono\wasm\emsdk" (
51+
if not exist "%__repoRoot%\src\mono\wasm\emsdk" (
5252
echo Error: Should set EMSDK_PATH environment variable pointing to emsdk root.
5353
exit /B 1
5454
)
5555

56-
set EMSDK_PATH=%__repoRoot%src\mono\wasm\emsdk
57-
set EMSDK_PATH=!EMSDK_PATH:\=/!
56+
set EMSDK_PATH=%__repoRoot%\src\mono\wasm\emsdk
5857
)
58+
:: replace backslash with forward slash and append last slash
59+
set "EMSDK_PATH=!EMSDK_PATH:\=/!"
60+
if not "!EMSDK_PATH:~-1!" == "/" set "EMSDK_PATH=!EMSDK_PATH!/"
5961

6062
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_TOOLCHAIN_FILE=!EMSDK_PATH!/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"
6163
set __UseEmcmake=1
6264
)
6365
if /i "%__Os%" == "wasi" (
64-
echo Error: WASI build not implemented on Windows yet
65-
exit /B 1
66+
if "%WASI_SDK_PATH%" == "" (
67+
if not exist "%__repoRoot%\src\mono\wasi\wasi-sdk" (
68+
echo Error: Should set WASI_SDK_PATH environment variable pointing to emsdk root.
69+
exit /B 1
70+
)
71+
72+
set WASI_SDK_PATH=%__repoRoot%src\mono\wasi\wasi-sdk
73+
)
74+
:: replace backslash with forward slash and append last slash
75+
set "WASI_SDK_PATH=!WASI_SDK_PATH:\=/!"
76+
if not "!WASI_SDK_PATH:~-1!" == "/" set "WASI_SDK_PATH=!WASI_SDK_PATH!/"
77+
set __CmakeGenerator=Ninja
78+
set __ExtraCmakeParams=%__ExtraCmakeParams% -DCLR_CMAKE_TARGET_OS=WASI -DCLR_CMAKE_TARGET_ARCH=wasm "-DWASI_SDK_PREFIX=!WASI_SDK_PATH!" "-DCMAKE_TOOLCHAIN_FILE=!WASI_SDK_PATH!/share/cmake/wasi-sdk.cmake" "-DCMAKE_SYSROOT=!WASI_SDK_PATH!/share/wasi-sysroot"
6679
)
6780
) else (
6881
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_SYSTEM_VERSION=10.0"

eng/pipelines/common/platform-matrix.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,27 @@ jobs:
358358
crossBuild: true
359359
${{ insert }}: ${{ parameters.jobParameters }}
360360

361+
# WASI WebAssembly
362+
363+
- ${{ if containsValue(parameters.platforms, 'wasi_wasm') }}:
364+
- template: xplat-setup.yml
365+
parameters:
366+
jobTemplate: ${{ parameters.jobTemplate }}
367+
helixQueuesTemplate: ${{ parameters.helixQueuesTemplate }}
368+
variables: ${{ parameters.variables }}
369+
osGroup: wasi
370+
archType: wasm
371+
targetRid: wasi-wasm
372+
platform: wasi_wasm
373+
shouldContinueOnError: ${{ parameters.shouldContinueOnError }}
374+
container: wasi_wasm
375+
jobParameters:
376+
hostedOs: Linux
377+
runtimeFlavor: ${{ parameters.runtimeFlavor }}
378+
stagedBuild: ${{ parameters.stagedBuild }}
379+
buildConfig: ${{ parameters.buildConfig }}
380+
${{ insert }}: ${{ parameters.jobParameters }}
381+
361382
# Browser WebAssembly
362383

363384
- ${{ if containsValue(parameters.platforms, 'Browser_wasm') }}:

eng/pipelines/common/templates/pipeline-with-resources.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ resources:
6060
- container: Browser_wasm
6161
image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-18.04-webassembly
6262

63+
- container: wasi_wasm
64+
image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-20.04-webassembly
65+
6366
- container: FreeBSD_x64
6467
image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-18.04-cross-freebsd-12
6568
env:
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
parameters:
2+
alwaysRun: false
3+
extraBuildArgs: ''
4+
isExtraPlatformsBuild: false
5+
nameSuffix: ''
6+
platforms: []
7+
8+
jobs:
9+
10+
#
11+
# Build for WASI/wasm and test it
12+
#
13+
- template: /eng/pipelines/common/platform-matrix.yml
14+
parameters:
15+
jobTemplate: /eng/pipelines/common/global-build-job.yml
16+
helixQueuesTemplate: /eng/pipelines/libraries/helix-queues-setup.yml
17+
buildConfig: Release
18+
runtimeFlavor: mono
19+
platforms: ${{ parameters.platforms }}
20+
variables:
21+
# map dependencies variables to local variables
22+
- name: alwaysRunVar
23+
value: ${{ parameters.alwaysRun }}
24+
- name: shouldRunOnDefaultPipelines
25+
value: $[
26+
or(
27+
eq(variables['wasmDarcDependenciesChanged'], true),
28+
eq(dependencies.evaluate_paths.outputs['SetPathVars_libraries.containsChange'], true),
29+
and(
30+
eq(dependencies.evaluate_paths.outputs['SetPathVars_wasm.containsChange'], true),
31+
eq(dependencies.evaluate_paths.outputs['SetPathVars_non_runtimetests.containsChange'], true)),
32+
eq(dependencies.evaluate_paths.outputs['SetPathVars_wasm_libraries.containsChange'], true),
33+
eq(dependencies.evaluate_paths.outputs['SetPathVars_mono_excluding_wasm.containsChange'], true))
34+
]
35+
jobParameters:
36+
isExtraPlatforms: ${{ parameters.isExtraPlatformsBuild }}
37+
testGroup: innerloop
38+
nameSuffix: ${{ parameters.nameSuffix }}_BuildOnly
39+
buildArgs: -s mono+libs+host -c $(_BuildConfig) /p:ArchiveTests=true ${{ parameters.extraBuildArgs }}
40+
timeoutInMinutes: 240
41+
# if !alwaysRun, then:
42+
# if this is runtime-wasm (isWasmOnlyBuild):
43+
# - then run only if it would not have run on default pipelines (based
44+
# on path changes)
45+
# - else run based on path changes
46+
condition: >-
47+
or(
48+
eq(variables['alwaysRunVar'], true),
49+
eq(variables['isDefaultPipeline'], variables['shouldRunOnDefaultPipelines']))

eng/pipelines/common/templates/wasm-library-tests.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,8 @@ jobs:
7171
eq(variables['alwaysRunVar'], true),
7272
eq(variables['isDefaultPipeline'], variables['shouldRunOnDefaultPipelines']))
7373
# extra steps, run tests
74-
extraStepsTemplate: /eng/pipelines/common/templates/additional-steps-then-helix.yml
74+
extraStepsTemplate: /eng/pipelines/libraries/helix.yml
7575
extraStepsParameters:
76-
additionalSteps:
77-
- ${{ if eq(parameters.buildAndRunWasi, true) }}:
78-
- script: >-
79-
make -C src/mono/wasi provision-deps all &&
80-
make -C src/mono/wasi/sample/console run
81-
name: build_wasi
82-
displayName: Build WASI, and run a sample
83-
8476
creator: dotnet-bot
8577
testRunNamePrefixSuffix: Mono_$(_BuildConfig)
8678
extraHelixArguments: /p:BrowserHost=$(_hostedOs) $(_wasmRunSmokeTestsOnlyArg) ${{ parameters.extraHelixArgs }}

0 commit comments

Comments
 (0)