Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e9805a2
Add System.Globalization.Native builds for iOS-like platforms
filipnavara Feb 20, 2023
9092d1c
Update package manifest
filipnavara Feb 21, 2023
e78a32d
Move copying of ICU static libs and data files from Mono to libs.native
filipnavara Feb 21, 2023
c83a2dc
Mono: Link static ICU shim only into Mono shared libraries
filipnavara Feb 21, 2023
628cb70
Include ICU .dat files in LibrariesRuntimeFiles
filipnavara Feb 21, 2023
3689be7
Build System.Globalization.Native on Browser/WASI
filipnavara Feb 21, 2023
2edeebd
Fix configuration options for WASM/WASI builds
filipnavara Feb 21, 2023
5ec149f
Update src/libraries/native-binplace.proj to include ICU .dat files
filipnavara Feb 21, 2023
3156ff7
List correct libraries in link_libraries
filipnavara Feb 21, 2023
556fc43
Fix iOS build after the link fix :/
filipnavara Feb 21, 2023
a92c289
Use correct ICU build for browser-wasm-threads builds
filipnavara Feb 21, 2023
a202612
Attempt to fix WASI build
filipnavara Feb 21, 2023
ccfd1e1
Fix libSystem.Globalization.Native.a output name for WASI
filipnavara Feb 22, 2023
122c1fa
Fix merge
filipnavara Feb 22, 2023
67b0a6e
Fix multithread browser builds
filipnavara Feb 22, 2023
560e08f
Fix WASI linking
filipnavara Feb 22, 2023
a57c67e
Revert WASI changes after rebase
filipnavara Feb 23, 2023
8371518
Try to fix builds on Windows
filipnavara Feb 23, 2023
fa9b2ff
Remove unnecessary icucore change
filipnavara Mar 4, 2023
5d0700a
Remove unnecessary empty line
filipnavara Mar 4, 2023
8e07a43
Wrap icu_trace_data in `#if defined(ICU_TRACING)`
filipnavara Mar 4, 2023
80cc2dc
Merge branch 'main' into icu-ios
akoeplinger Apr 24, 2023
3c823b8
Fix "unused parameter 'symbolVersion'" error
akoeplinger Apr 24, 2023
42ae535
Fix NativeAOT build for Apple Mobile
akoeplinger Apr 25, 2023
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
1 change: 1 addition & 0 deletions eng/liveBuilds.targets
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
<ExcludeNativeLibrariesRuntimeFiles Condition="'$(IncludeOOBLibraries)' != 'true'"
Include="$(LibrariesNativeArtifactsPath)libSystem.IO.Ports.Native.*" />
<LibrariesRuntimeFiles Include="
$(LibrariesNativeArtifactsPath)*.dat;
$(LibrariesNativeArtifactsPath)*.dll;
$(LibrariesNativeArtifactsPath)*.dylib;
$(LibrariesNativeArtifactsPath)*.a;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ The .NET Foundation licenses this file to you under the MIT license.

<ItemGroup>
<NetCoreAppNativeLibrary Include="System.Native" />
<!-- FIXME: The library is currently not available for iOS-like platforms -->
<NetCoreAppNativeLibrary Include="System.Globalization.Native" Condition="'$(StaticICULinking)' != 'true' and '$(_IsiOSLikePlatform)' != 'true'" />
<NetCoreAppNativeLibrary Include="System.Globalization.Native" Condition="'$(StaticICULinking)' != 'true'" />
<NetCoreAppNativeLibrary Include="System.IO.Compression.Native" />
<NetCoreAppNativeLibrary Include="System.Net.Security.Native" />
<NetCoreAppNativeLibrary Include="System.Security.Cryptography.Native.Apple" Condition="'$(_IsApplePlatform)' == 'true'" />
Expand Down
9 changes: 9 additions & 0 deletions src/coreclr/runtime.proj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

<PropertyGroup>
<NativeBuildPartitionPropertiesToRemove>ClrFullNativeBuild;ClrRuntimeSubset;ClrJitSubset;ClrPalTestsSubset;ClrAllJitsSubset;ClrILToolsSubset;ClrNativeAotSubset;ClrSpmiSubset;ClrCrossComponentsSubset;HostArchitecture;PgoInstrument;NativeOptimizationDataSupported;CMakeArgs</NativeBuildPartitionPropertiesToRemove>
<_IcuDir Condition="'$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)' != ''">$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)/runtimes/$(TargetOS)-$(TargetArchitecture)$(_RuntimeVariant)/native</_IcuDir>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="runtime-prereqs.proj" GlobalPropertiesToRemove="$(NativeBuildPartitionPropertiesToRemove)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetsAppleMobile)' == 'true'">
<PackageReference Include="Microsoft.NETCore.Runtime.ICU.Transport" PrivateAssets="all" Version="$(MicrosoftNETCoreRuntimeICUTransportVersion)" GeneratePathProperty="true" />
</ItemGroup>

<Import Project="$(RepositoryEngineeringDir)nativepgo.targets" />

<Target Name="BuildRuntime"
Expand Down Expand Up @@ -52,6 +57,10 @@
<_CoreClrBuildArg Condition="'$(ClrCrossComponentsSubset)' == 'true'" Include="-component crosscomponents" />
</ItemGroup>

<ItemGroup Condition="'$(TargetsAppleMobile)' == 'true'">
<_CoreClrBuildArg Include="-cmakeargs -DCMAKE_ICU_DIR=&quot;$(_IcuDir)&quot;" />
</ItemGroup>

<PropertyGroup>
<_CoreClrBuildScript Condition="$([MSBuild]::IsOsPlatform(Windows))">build-runtime.cmd</_CoreClrBuildScript>
<_CoreClrBuildScript Condition="!$([MSBuild]::IsOsPlatform(Windows))">build-runtime.sh</_CoreClrBuildScript>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<PlatformManifestFileEntry Include="System.Private.Xml.dll" />
<PlatformManifestFileEntry Include="System.Private.Xml.Linq.dll" />
<!-- Native libraries -->
<PlatformManifestFileEntry Include="libSystem.Globalization.Native.a" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Globalization.Native.dylib" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Globalization.Native.so" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.IO.Compression.Native.a" IsNative="true" />
Expand Down
1 change: 1 addition & 0 deletions src/libraries/native-binplace.proj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<BinPlaceItem Include="$(NativeBinDir)*.dwarf" />
<BinPlaceItem Include="$(NativeBinDir)*.dex" />
<BinPlaceItem Include="$(NativeBinDir)*.jar" />
<BinPlaceItem Include="$(NativeBinDir)*.dat" />
<FileWrites Include="@(BinPlaceItem)" />
</ItemGroup>
</Target>
Expand Down
12 changes: 0 additions & 12 deletions src/mono/mono.proj
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,6 @@
<_MonoRuntimeFilePath>$(MonoObjDir)out\lib\$(MonoFileName)</_MonoRuntimeFilePath>
<_MonoRuntimeStaticFilePath Condition="'$(TargetsMacCatalyst)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsAndroid)' == 'true' or '$(TargetsLinuxBionic)' == 'true'">$(MonoObjDir)out\lib\$(MonoStaticLibFileName)</_MonoRuntimeStaticFilePath>
<_MonoIncludeInterpStaticFiles Condition="'$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true'">true</_MonoIncludeInterpStaticFiles>
<_MonoIncludeIcuFiles Condition="'$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsMacCatalyst)' == 'true'">true</_MonoIncludeIcuFiles>
</PropertyGroup>
<PropertyGroup Condition="'$(BuildMonoAOTCrossCompiler)' == 'true'">
<_MonoAotCrossFilePath>$(MonoObjCrossDir)out\bin\$(MonoAotCrossFileName)</_MonoAotCrossFilePath>
Expand Down Expand Up @@ -1039,19 +1038,8 @@
<_MonoICorDebugArtifacts Condition="'$(MonoMsCorDbi)' == 'true'" Include="$(MonoObjDir)out\lib\$(LibPrefix)mscordbi$(LibSuffix)">
<Destination>$(RuntimeBinDir)$(LibPrefix)mscordbi$(LibSuffix)</Destination>
</_MonoICorDebugArtifacts>

<_IcuArtifacts Condition="'$(_MonoIncludeIcuFiles)' == 'true'"
Include="$(_IcuLibdir)\libicuuc.a;
$(_IcuLibdir)\libicui18n.a;
$(_IcuLibdir)\libicudata.a;
$(_IcuLibdir)\*.dat" />
</ItemGroup>

<Copy Condition="'$(_MonoIncludeIcuFiles)' == 'true'"
SourceFiles="@(_IcuArtifacts)"
DestinationFolder="$(RuntimeBinDir)"
SkipUnchangedFiles="true" />

<Copy SourceFiles="@(_MonoRuntimeArtifacts)"
DestinationFiles="%(_MonoRuntimeArtifacts.Destination)"
Condition="'$(MonoGenerateOffsetsOSGroups)' == ''"
Expand Down
17 changes: 15 additions & 2 deletions src/mono/mono/mini/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ if(HAVE_SYS_ICU)
if(ICU_LIBDIR)
set(ICU_LDFLAGS "-L${ICU_LIBDIR}")
endif()

add_library(icu_shim_objects OBJECT "${icu_shim_sources}")
set(HAVE_ICU_SHIM 1)
endif()

#
Expand Down Expand Up @@ -350,7 +353,7 @@ if(HOST_WIN32)
set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_OPTIONS "/wd4005;/wd4127;/wd4131;/wd4244")
endif()

set(monosgen-sources "${icu_shim_sources};${mini_sources};${ZLIB_SOURCES}")
set(monosgen-sources "${mini_sources};${ZLIB_SOURCES}")

add_library(monosgen-objects OBJECT "${monosgen-sources}")
target_link_libraries (monosgen-objects PRIVATE monoapi eglib_api utils_objects sgen_objects metadata_objects)
Expand Down Expand Up @@ -379,6 +382,9 @@ if(NOT DISABLE_SHARED_LIBS)
endif(CLR_CMAKE_HOST_ALPINE_LINUX AND TARGET_S390X)
set_target_properties(monosgen-shared PROPERTIES OUTPUT_NAME ${MONO_SHARED_LIB_NAME})
target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects)
if(HAVE_ICU_SHIM)
target_link_libraries(monosgen-shared PRIVATE icu_shim_objects)
endif()
target_include_directories (monosgen-shared PRIVATE monoapi)
if(TARGET_WIN32)
# on Windows the import library for the shared mono library will have the same name as the static library,
Expand Down Expand Up @@ -436,6 +442,9 @@ if(NOT DISABLE_SHARED_LIBS)
add_library(${frameworkconfig} SHARED $<TARGET_OBJECTS:monosgen-objects>)
target_compile_definitions(${frameworkconfig} PRIVATE -DMONO_DLL_EXPORT)
target_link_libraries(${frameworkconfig} PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects)
if(HAVE_ICU_SHIM)
target_link_libraries(${frameworkconfig} PRIVATE icu_shim_objects)
endif()
target_link_libraries(${frameworkconfig} PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${ICU_LIBS} ${Z_LIBS})

if(ICU_LDFLAGS)
Expand Down Expand Up @@ -538,7 +547,11 @@ if(NOT DISABLE_EXECUTABLES)
if(MONO_CROSS_COMPILE_EXECUTABLE_NAME)
set_target_properties(mono-sgen PROPERTIES OUTPUT_NAME mono-aot-cross)
endif()
target_link_libraries(mono-sgen PRIVATE monoapi eglib_api monosgen-static ${OS_LIBS} ${LLVM_LIBS} ${ICU_LIBS} ${Z_LIBS})
target_link_libraries(mono-sgen PRIVATE monoapi eglib_api monosgen-static)
if(HAVE_ICU_SHIM)
target_link_libraries(mono-sgen PRIVATE icu_shim_objects)
endif()
target_link_libraries(mono-sgen PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${ICU_LIBS} ${Z_LIBS})
# Alpine Linux implements ucontext in a different library
if(CLR_CMAKE_HOST_ALPINE_LINUX AND TARGET_S390X)
target_link_libraries(mono-sgen PRIVATE ucontext)
Expand Down
1 change: 1 addition & 0 deletions src/mono/wasi/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ target_link_libraries(dotnet
${MONO_ARTIFACTS_DIR}/libmono-icall-table.a
${NATIVE_BIN_DIR}/wasm-bundled-timezones.a
${NATIVE_BIN_DIR}/libSystem.Native.a
${NATIVE_BIN_DIR}/libSystem.Globalization.Native.a
${NATIVE_BIN_DIR}/libSystem.IO.Compression.Native.a
)

Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ target_link_libraries(dotnet
${MONO_ARTIFACTS_DIR}/libmono-profiler-browser.a
${NATIVE_BIN_DIR}/wasm-bundled-timezones.a
${NATIVE_BIN_DIR}/libSystem.Native.a
${NATIVE_BIN_DIR}/libSystem.Globalization.Native.a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must admit I don't understand big picture. Could you please explain the consequences of this for browser ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of building the ICU shim as part of the Mono runtime build, it moves the build to libs.native part of the build. Then it links the resulting static library back.

The end result should be roughly identical to the previous status quo.

There are several reasons for this change:

  • Reuse of the build system in libs.native instead of maintaining a second copy in Mono build
  • iOS-like platforms need the library for both Mono and NativeAOT, so building it as part of Mono runtime is problematic; it can be shared by both runtimes this way
  • Browser/WASI are just changed to follow the same pattern to make the build system less complicated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @steveisok LibraryBuilder targets should also be aware of this change (although I suspect it doesn't matter to the library builder where the static lib came from, as long as it's there)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from what I can see the LibraryBuilder doesn't need updating since it just takes all *.a files

${NATIVE_BIN_DIR}/libSystem.IO.Compression.Native.a)

set_target_properties(dotnet PROPERTIES
Expand Down
2 changes: 1 addition & 1 deletion src/native/libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
endif ()

add_subdirectory(System.Native)
add_subdirectory(System.Globalization.Native)

if (CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
# skip for now
Expand All @@ -183,7 +184,6 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
elseif (FORCE_ANDROID_OPENSSL)
add_subdirectory(System.Security.Cryptography.Native)
else ()
add_subdirectory(System.Globalization.Native)
add_subdirectory(System.Net.Security.Native)
add_subdirectory(System.Security.Cryptography.Native)
endif ()
Expand Down
4 changes: 2 additions & 2 deletions src/native/libs/Common/pal_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#if defined(TARGET_UNIX)
#if defined(TARGET_UNIX) || defined(TARGET_WASI)
#include <stdatomic.h>
#elif defined(TARGET_WINDOWS)
#include "windows.h"
Expand All @@ -13,7 +13,7 @@
// The args passed in should match InterlockedCompareExchangePointer Windows API
static int pal_atomic_cas_ptr(void* volatile* dest, void* exchange, void* comparand)
{
#if defined(TARGET_UNIX)
#if defined(TARGET_UNIX) || defined(TARGET_WASI)
return __atomic_compare_exchange_n(dest, &comparand, exchange, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
#elif defined(TARGET_WINDOWS)
return InterlockedCompareExchangePointer(dest, exchange, comparand) == comparand;
Expand Down
30 changes: 21 additions & 9 deletions src/native/libs/System.Globalization.Native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
project(System.Globalization.Native C)

if(CLR_CMAKE_TARGET_UNIX)
if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI)
add_compile_options(-Wno-switch-enum)
add_compile_options(-Wno-covered-switch-default)

# Workaround for warnings produced by ICU headers
add_compile_options(-Wno-reserved-id-macro)
add_compile_options(-Wno-documentation)
add_compile_options(-Wno-documentation-unknown-command)
add_compile_options(-Wno-reserved-identifier)

# Workaround for https://unicode-org.atlassian.net/browse/ICU-20601
add_compile_options(-Wno-extra-semi-stmt)
add_compile_options(-Wno-unknown-warning-option)

if (NOT CLR_CMAKE_TARGET_ANDROID)
if (CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST)
if (NOT CLR_CMAKE_TARGET_ANDROID AND NOT DEFINED CMAKE_ICU_DIR)
if (CLR_CMAKE_TARGET_OSX)
execute_process(COMMAND brew --prefix OUTPUT_VARIABLE brew_prefix OUTPUT_STRIP_TRAILING_WHITESPACE)
set(ICU_HOMEBREW_INC_PATH "${brew_prefix}/opt/icu4c/include")
endif()
Expand All @@ -25,7 +26,7 @@ if(CLR_CMAKE_TARGET_UNIX)
return()
endif()

if(CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST)
if(CLR_CMAKE_TARGET_OSX)
add_definitions(-DOSX_ICU_LIBRARY_PATH="/usr/lib/libicucore.dylib")
add_definitions(-DU_DISABLE_RENAMING)
else()
Expand Down Expand Up @@ -59,6 +60,17 @@ set(NATIVEGLOBALIZATION_SOURCES
pal_normalization.c
)

if (DEFINED CMAKE_ICU_DIR)
include_directories(${CMAKE_ICU_DIR}/include)
link_libraries(${CMAKE_ICU_DIR}/lib/libicuuc.a ${CMAKE_ICU_DIR}/lib/libicui18n.a ${CMAKE_ICU_DIR}/lib/libicudata.a)
link_libraries(stdc++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why did we not have to do this in mono?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@filipnavara filipnavara Mar 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It always happens somewhere, either at linking the runtime as dynamic library, or as part of the final linking of the application.

In this particular case we happen to build .dylib for iOS which may not be strictly necessary. Since the project is marked as using the "C" language and not "CXX" the C++ standard library is not included implicitly.

We can exclude the .dylib builds for iOS-like platforms as an alternative (but that will exclude all the dylib builds of native libs, so there could be some unforeseen consequences).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'm mostly worried about Android where we can't introduce this stdc++ dependency. For Android we're loading ICU .so via dlopen from the system location so we just need to make sure this doesn't apply for Android.

I'd probably move the two link_libraries down to the condition where we set STATIC_ICU for iOS/Catalyst etc

Copy link
Member Author

@filipnavara filipnavara Mar 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Android you will end up linking to the libmono*.so that has the ICU shim built-in. This PR doesn't affect that. We do build an additional libSystem.Globalization.Native.[a/so] and it likely is not necessary. While not necessary for the supported configurations, it is nice to have for the unsupported NativeAOT/Android builds.

endif()

if (CMAKE_USE_PTHREADS)
add_compile_options(-pthread)
add_linker_flag(-pthread)
endif()

if (LOCAL_BUILD)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim_static.c)
Expand All @@ -69,6 +81,9 @@ if (LOCAL_BUILD)
# For minipal files
include_directories(../../)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
elseif (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
add_definitions(-DSTATIC_ICU)
set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim_static.c)
else()
set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim.c)
endif()
Expand All @@ -82,10 +97,6 @@ if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI)
set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_timeZoneInfo.c)
endif()

if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI)
set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} entrypoints.c)
endif()

if (MSVC)
set_source_files_properties(${NATIVEGLOBALIZATION_SOURCES} PROPERTIES LANGUAGE CXX)
endif()
Expand Down Expand Up @@ -116,9 +127,10 @@ endif()
add_library(System.Globalization.Native-Static
STATIC
${NATIVEGLOBALIZATION_SOURCES}
entrypoints.c
)

if(CLR_CMAKE_TARGET_UNIX)
if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI)
set_target_properties(System.Globalization.Native-Static PROPERTIES OUTPUT_NAME System.Globalization.Native CLEAN_DIRECT_OUTPUT 1)
endif()

Expand Down
3 changes: 2 additions & 1 deletion src/native/libs/System.Globalization.Native/config.h.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once

#cmakedefine01 HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS
#cmakedefine01 HAVE_SET_MAX_VARIABLE
#cmakedefine01 HAVE_SET_MAX_VARIABLE
#cmakedefine01 HAVE_UCOL_CLONE
3 changes: 2 additions & 1 deletion src/native/libs/System.Globalization.Native/configure.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
if(CLR_CMAKE_TARGET_ANDROID OR CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST)
if(CLR_CMAKE_TARGET_ANDROID OR CLR_CMAKE_TARGET_APPLE OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
set(HAVE_SET_MAX_VARIABLE 1)
set(HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS 1)
set(HAVE_UCOL_CLONE 0)
else()
include(CheckCSourceCompiles)
include(CheckSymbolExists)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "pal_errors_internal.h"
#include "pal_calendarData.h"

#if defined(TARGET_UNIX)
#if defined(TARGET_UNIX) || defined(TARGET_WASI)
#include <strings.h>

#define STRING_COPY(destination, numberOfElements, source) \
Expand Down
1 change: 1 addition & 0 deletions src/native/libs/System.Globalization.Native/pal_icushim.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ static void InitializeVariableMaxAndTopPointers(char* symbolVersion)
#if defined(TARGET_OSX) || defined(TARGET_ANDROID)
// OSX and Android always run against ICU version which has ucol_setMaxVariable.
// We shouldn't come here.
(void)symbolVersion;
assert(false);
#elif defined(TARGET_WINDOWS)
char symbolName[SYMBOL_NAME_SIZE];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#pragma once

#if defined(TARGET_UNIX)
#if defined(TARGET_UNIX) || defined(TARGET_WASI)

#include "config.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ static void log_icu_error(const char* name, UErrorCode status)
log_shim_error("ICU call %s failed with error #%d '%s'.", name, status, statusText);
}

#if defined(ICU_TRACING)
static void U_CALLCONV icu_trace_data(const void* context, int32_t fnNumber, int32_t level, const char* fmt, va_list args)
{
char buf[1000];
utrace_vformat(buf, sizeof(buf), 0, fmt, args);
printf("[ICUDT] %s: %s\n", utrace_functionName(fnNumber), buf);
}
#endif

static int32_t load_icu_data(const void* pData);

Expand Down Expand Up @@ -127,7 +129,7 @@ cstdlib_load_icu_data(const char *path)
goto error;
}

file_buf = malloc(sizeof(char) * (file_buf_size + 1));
file_buf = malloc(sizeof(char) * (unsigned long)(file_buf_size + 1));

if (file_buf == NULL)
{
Expand All @@ -141,7 +143,7 @@ cstdlib_load_icu_data(const char *path)
goto error;
}

fread(file_buf, sizeof(char), file_buf_size, fp);
fread(file_buf, sizeof(char), (unsigned long)file_buf_size, fp);
if (ferror( fp ) != 0)
{
log_shim_error("Unable to read ICU dat file");
Expand Down
11 changes: 11 additions & 0 deletions src/native/libs/build-native.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ set __BuildTarget="build"
set __TargetOS=windows
set CMAKE_BUILD_TYPE=Debug
set __Ninja=1
set __icuDir=""
set __usePThreads=0

:Arg_Loop
:: Since the native build requires some configuration information before msbuild is called, we have to do some manual args parsing
Expand All @@ -42,6 +44,9 @@ if /i [%1] == [rebuild] ( set __BuildTarget=rebuild&&shift&goto Arg_Loop)

if /i [%1] == [msbuild] ( set __Ninja=0&&shift&goto Arg_Loop)

if /i [%1] == [icudir] ( set __icuDir=%2&&shift&&shift&goto Arg_Loop)
if /i [%1] == [usepthreads] ( set __usePThreads=1&&shift&goto Arg_Loop)

shift
goto :Arg_Loop

Expand All @@ -60,6 +65,12 @@ set __cmakeRepoRoot=%__repoRoot:\=/%
set __ExtraCmakeParams="-DCMAKE_REPO_ROOT=%__cmakeRepoRoot%"
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%"

if NOT %__icuDir% == "" (
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_ICU_DIR=%__icuDir%"
)
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_USE_PTHREADS=%__usePThreads%"


if [%__outConfig%] == [] set __outConfig=%__TargetOS%-%__BuildArch%-%CMAKE_BUILD_TYPE%

if %__CMakeBinDir% == "" (
Expand Down
Loading