Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<DefaultCoreClrSubsets Condition="'$(TargetsAndroid)' == 'true'">clr.native+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs+clr.crossarchtools</DefaultCoreClrSubsets>
<DefaultCoreClrSubsets Condition="'$(TargetsAppleMobile)' == 'true'">clr.native+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs+clr.crossarchtools</DefaultCoreClrSubsets>
<DefaultCoreClrSubsets Condition="'$(TargetsBrowser)' == 'true'">provision.emsdk+clr.native+clr.corelib+clr.nativecorelib+clr.tools+clr.packages+clr.crossarchtools+libs.native+host.native</DefaultCoreClrSubsets>
<DefaultCoreClrSubsets Condition="'$(TargetsWasi)' == 'true'">clr.native+clr.corelib+clr.nativecorelib+clr.tools+clr.packages+clr.crossarchtools+libs.native</DefaultCoreClrSubsets>
<DefaultCoreClrSubsets Condition="'$(TargetsWasi)' == 'true'">clr.native+clr.corelib+clr.nativecorelib+clr.tools+clr.packages+clr.crossarchtools+libs.native+host.native</DefaultCoreClrSubsets>
<!-- Even on platforms that do not support the CoreCLR runtime, we still want to build ilasm/ildasm. -->
<DefaultCoreClrSubsets Condition="'$(RuntimeFlavor)' != 'CoreCLR'">clr.iltools+clr.packages</DefaultCoreClrSubsets>

Expand Down
10 changes: 6 additions & 4 deletions eng/liveBuilds.targets
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,12 @@
IsNative="true" />
</ItemGroup>

<!-- WASI CoreCLR ships only the static runtime libraries (already
provided by RuntimeFiles from $(CoreCLRSharedFrameworkDir)) and
the libs.native static libs (already provided by the unconditional
glob above). corerun.wasm is not part of the runtime pack. -->
<!-- WASI CoreCLR host archive, staged from the host subset. Excluded from the runtime-tests
build (which omits the host subset), mirroring the browser libBrowserHost.a handling. -->
<ItemGroup Condition="'$(TargetOS)' == 'wasi' and '$(RuntimeFlavor)' == 'CoreCLR' and '$(IsTestsCommonProject)' != 'true'">
<LibrariesRuntimeFiles Include="$(HostSharedFrameworkDir)libWasiHost.a"
IsNative="true" />
</ItemGroup>


<Error Condition="'@(LibrariesRuntimeFiles)' == ''" Text="The 'libs' subset must be built before building this project." />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
<PlatformManifestFileEntry Include="libSystem.Runtime.InteropServices.JavaScript.Native.js" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Runtime.InteropServices.JavaScript.Native.js.map" IsNative="true" />
<!-- wasi specific -->
<PlatformManifestFileEntry Include="libWasiHost.a" IsNative="true" />
<PlatformManifestFileEntry Include="main.c" IsNative="true" />
<PlatformManifestFileEntry Include="driver.h" IsNative="true" />
<PlatformManifestFileEntry Include="stubs.c" IsNative="true" />
Expand Down
7 changes: 5 additions & 2 deletions src/native/corehost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ if(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_SUNOS)
add_link_options(LINKER:-Bsymbolic)
endif()

if(NOT CLR_CMAKE_TARGET_BROWSER)
if(NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI)
add_library(fxr_resolver INTERFACE)
target_sources(fxr_resolver INTERFACE fxr_resolver.c)
target_include_directories(fxr_resolver INTERFACE fxr)
Expand Down Expand Up @@ -112,9 +112,12 @@ if(NOT CLR_CMAKE_TARGET_BROWSER)
if(CLR_CMAKE_BUILD_HOST_TESTS)
add_subdirectory(test)
endif()
else()
elseif(CLR_CMAKE_TARGET_BROWSER)
add_subdirectory(hostmisc)
add_subdirectory(browserhost)
else() # CLR_CMAKE_TARGET_WASI
# The wasi host is self-contained (shares the corerun pal header, no hostmisc dependency).
add_subdirectory(wasihost)
endif()

# If there's a dynamic ASAN runtime, then install it in the directories where we put our executables.
Expand Down
29 changes: 27 additions & 2 deletions src/native/corehost/corehost.proj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<BuildCoreHostDependsOn>GenerateRuntimeVersionFile</BuildCoreHostDependsOn>
<BuildCoreHostDependsOn Condition="'$(EnableSourceControlManagerQueries)' == 'true'">$(BuildCoreHostDependsOn);InitializeSourceControlInformationFromSourceControlManager</BuildCoreHostDependsOn>
<BuildCoreHostDependsOn Condition="'$(TargetsBrowser)' == 'true'">AcquireEmscriptenSdk;$(BuildCoreHostDependsOn);GenerateEmccExports;ResolveRuntimeFilesFromLocalBuild</BuildCoreHostDependsOn>
<!-- WASI: the corehost native build needs the wasi-sdk (WASI_SDK_PATH, passed below). -->
<BuildCoreHostDependsOn Condition="'$(TargetsWasi)' == 'true'">AcquireWasiSdk;$(BuildCoreHostDependsOn)</BuildCoreHostDependsOn>
<CopyWasmNativeFilesDependsOn Condition="'$(TargetOS)' == 'windows'">BuildCoreHostOnWindows</CopyWasmNativeFilesDependsOn>
<CopyWasmNativeFilesDependsOn Condition="'$(TargetOS)' != 'windows'">BuildCoreHostOnUnix</CopyWasmNativeFilesDependsOn>
<IntermediateOutputRootPath>$(ArtifactsObjDir)$(TargetRid).$(Configuration)\</IntermediateOutputRootPath>
Expand Down Expand Up @@ -92,12 +94,17 @@
<BuildArgs>$(BuildArgs) -cmakeargs "-DCLR_CMAKE_BUILD_HOST_PRODUCT=$(BuildNativeHostProduct.ToUpper())"</BuildArgs>
</PropertyGroup>

<!-- WASI: pass the acquired wasi-sdk to the native build. -->
<PropertyGroup Condition="'$(TargetsWasi)' == 'true'">
<_CoreHostBuildEnvironmentVariables>WASI_SDK_PATH=$(RuntimeBuildWasiSdkPath)</_CoreHostBuildEnvironmentVariables>
</PropertyGroup>

<!--
Use IgnoreStandardErrorWarningFormat because Arcade sets WarnAsError and we want to avoid
upgrading compiler warnings to errors in release branches.
-->
<Message Text="&quot;$(BuildScript)&quot; $(BuildArgs) @(NativeCMakeArg, ' ')" Importance="High"/>
<Exec Command="&quot;$(BuildScript)&quot; $(BuildArgs) @(NativeCMakeArg, ' ')" IgnoreStandardErrorWarningFormat="true"/>
<Exec Command="&quot;$(BuildScript)&quot; $(BuildArgs) @(NativeCMakeArg, ' ')" IgnoreStandardErrorWarningFormat="true" EnvironmentVariables="$(_CoreHostBuildEnvironmentVariables)"/>
</Target>

<!--
Expand Down Expand Up @@ -169,13 +176,18 @@
<BuildArgs>$(BuildArgs) -cmakeargs "-DCLR_CMAKE_BUILD_HOST_PRODUCT=$(BuildNativeHostProduct.ToUpper())"</BuildArgs>
</PropertyGroup>

<!-- WASI: gen-buildsys.cmd needs WASI_SDK_PATH (set by the AcquireWasiSdk dependency above). -->
<PropertyGroup Condition="'$(TargetsWasi)' == 'true'">
<_CoreHostBuildEnvironmentVariables>WASI_SDK_PATH=$(RuntimeBuildWasiSdkPath)</_CoreHostBuildEnvironmentVariables>
</PropertyGroup>

<!--
Run script that invokes Cmake to create VS files, and then calls msbuild to compile them. Use
IgnoreStandardErrorWarningFormat because Arcade sets WarnAsError and we want to avoid
upgrading compiler warnings to errors in release branches.
-->
<Message Text="&quot;$(BuildScript)&quot; $(BuildArgs) @(NativeCMakeArg, ' ')" Importance="High"/>
<Exec Command="&quot;$(BuildScript)&quot; $(BuildArgs) @(NativeCMakeArg, ' ')" IgnoreStandardErrorWarningFormat="true"/>
<Exec Command="&quot;$(BuildScript)&quot; $(BuildArgs) @(NativeCMakeArg, ' ')" IgnoreStandardErrorWarningFormat="true" EnvironmentVariables="$(_CoreHostBuildEnvironmentVariables)"/>
</Target>

<Target Name="CopyWasmNativeFiles" AfterTargets="Build" DependsOnTargets="$(CopyWasmNativeFilesDependsOn)" Condition="'$(TargetsBrowser)' == 'true'">
Expand All @@ -197,6 +209,19 @@
SkipUnchangedFiles="true" />
</Target>

<!-- WASI CoreCLR: stage libWasiHost.a into the runtime pack native dir for the per-app relink,
mirroring the browser CopyWasmNativeFiles above. Depends on both host-build targets (one is
skipped by its HostOS condition) so the copy is ordered after the archive on either host. -->
<Target Name="CopyWasiNativeFiles" AfterTargets="Build" DependsOnTargets="BuildCoreHostOnUnix;BuildCoreHostOnWindows" Condition="'$(TargetsWasi)' == 'true' and '$(RuntimeFlavor)' == 'CoreCLR'">
<ItemGroup>
<_MicrosoftNetCoreAppRuntimePackNativeDirFiles Include="$(HostSharedFrameworkDir)libWasiHost.a" />
</ItemGroup>

<Copy SourceFiles="@(_MicrosoftNetCoreAppRuntimePackNativeDirFiles)"
DestinationFolder="$(MicrosoftNetCoreAppRuntimePackNativeDir)"
SkipUnchangedFiles="true" />
</Target>

<Target Name="PrependWindowsHeaderIncludeToVersionHeaderFile"
Condition="'$(TargetOS)' == 'windows'"
AfterTargets="GenerateNativeVersionFile">
Expand Down
42 changes: 42 additions & 0 deletions src/native/corehost/wasihost/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Licensed to the .NET Foundation under one or more agreements.
# The .NET Foundation licenses this file to you under the MIT license.

project(wasihost)
set(DOTNET_PROJECT_NAME "WasiHost-Static")

# HAVE_DIRENT_D_TYPE / HAVE_GETAUXVAL for the shared corerun pal header.
include(configure.cmake)

set(WASIHOST_SOURCES
./wasihost.cpp
)

# Reuse the corerun pal header (path/CORE_ROOT/TPA helpers); it's header-only, so no corerun object
# is linked here.
set(WASIHOST_CORERUN_DIR ${CLR_REPO_ROOT_DIR}/src/coreclr/hosts/corerun)

add_library(WasiHost-Static
STATIC
${WASIHOST_SOURCES}
)
set_target_properties(WasiHost-Static PROPERTIES OUTPUT_NAME WasiHost CLEAN_DIRECT_OUTPUT 1)

# The coreclr build sets these wasi emulation defines globally; the corehost build does not. The
# matching -lwasi-emulated-* libraries are supplied at the per-app relink.
if (CLR_CMAKE_TARGET_WASI)
target_compile_definitions(WasiHost-Static PRIVATE
_WASI_EMULATED_MMAN
_WASI_EMULATED_GETPID
_WASI_EMULATED_SIGNAL
_WASI_EMULATED_PROCESS_CLOCKS)
endif()

target_include_directories(WasiHost-Static PRIVATE
${CMAKE_CURRENT_BINARY_DIR} # generated config.h
${WASIHOST_CORERUN_DIR} # corerun.hpp (shared pal)
${CLR_SRC_NATIVE_DIR} # minipal/*.h
)

# The runtime static libraries and the app-generated callhelpers are supplied at the per-app relink
# by the CoreCLR-WASI app builder, which pulls this archive whole-archive for main().
install(TARGETS WasiHost-Static DESTINATION sharedFramework COMPONENT runtime)
10 changes: 10 additions & 0 deletions src/native/corehost/wasihost/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#ifndef __CONFIG_H__
#define __CONFIG_H__

#cmakedefine01 HAVE_GETAUXVAL
#cmakedefine01 HAVE_DIRENT_D_TYPE

#endif // __CONFIG_H__
15 changes: 15 additions & 0 deletions src/native/corehost/wasihost/configure.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Licensed to the .NET Foundation under one or more agreements.
# The .NET Foundation licenses this file to you under the MIT license.

# Mirrors src/coreclr/hosts/corerun/configure.cmake: the shared corerun pal header (corerun.hpp)
# consumes HAVE_DIRENT_D_TYPE / HAVE_GETAUXVAL from this generated config.h. The corehost build
# does not include the CMake check modules globally (unlike the coreclr build), so include them.
include(CheckSymbolExists)
include(CheckStructHasMember)

check_symbol_exists(getauxval sys/auxv.h HAVE_GETAUXVAL)
check_struct_has_member ("struct dirent" d_type dirent.h HAVE_DIRENT_D_TYPE)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h)
Loading
Loading