Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local build for System.Globalization shim #72896

Merged
merged 28 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
aed8b64
Add local build for System.Globalization shim
Jul 24, 2022
ec90686
Merge branch 'dotnet:main' into build
smhmhmd Aug 2, 2022
f2fa736
Incorporate review feedback
smhmhmd Aug 2, 2022
d8dabf2
Fix IlCompilerPackagePath
smhmhmd Aug 2, 2022
e548415
Address review feedback
smhmhmd Aug 2, 2022
6075e03
Incorporate review feedback
smhmhmd Aug 4, 2022
5256276
Merge branch 'dotnet:main' into build
smhmhmd Aug 8, 2022
3fcba3d
Address feedback from 08/04
Aug 8, 2022
3eba2de
Merge branch 'dotnet:main' into build
smhmhmd Aug 16, 2022
2f440a0
Fix DirectPInvoke for library built by user
Aug 16, 2022
9bf52ca
Merge branch 'dotnet:main' into build
smhmhmd Aug 22, 2022
de4b4fc
Merge branch 'dotnet:main' into build
smhmhmd Sep 1, 2022
e59cc03
Feedback on 08/25: rename static-build, "source_code" and cleanup com…
Aug 31, 2022
b51f34c
Merge branch 'dotnet:main' into build
smhmhmd Sep 1, 2022
1acc76f
Merge branch 'dotnet:main' into build
smhmhmd Sep 2, 2022
556dcf3
Merge branch 'dotnet:main' into build
smhmhmd Sep 2, 2022
4a67db0
Feedback on 09/02
Sep 3, 2022
ff907cf
Move file includes to previous itemgroup
Sep 4, 2022
0a11c50
Move file includes to previous itemgroup
smhmhmd Sep 4, 2022
68eac73
Merge branch 'build' of https://github.com/smhmhmd/runtime into build
smhmhmd Sep 4, 2022
907c322
Merge branch 'dotnet:main' into build
smhmhmd Sep 4, 2022
e5c2c51
Update section in compiling.md
smhmhmd Sep 4, 2022
40bf9be
Update src/coreclr/nativeaot/docs/compiling.md
jkotas Sep 5, 2022
5f9e7a7
Update src/coreclr/nativeaot/docs/compiling.md
jkotas Sep 5, 2022
e4fdcfa
Update src/coreclr/nativeaot/docs/compiling.md
jkotas Sep 5, 2022
7a96d14
Update src/coreclr/nativeaot/docs/compiling.md
smhmhmd Sep 5, 2022
8323197
Update src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microso…
smhmhmd Sep 5, 2022
bca6da8
Merge branch 'dotnet:main' into build
smhmhmd Sep 6, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The .NET Foundation licenses this file to you under the MIT license.

<ItemGroup>
<NetCoreAppNativeLibrary Include="System.Native" />
<NetCoreAppNativeLibrary Include="System.Globalization.Native" />
<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="'$(TargetOS)' == 'OSX'" />
Expand All @@ -67,13 +67,21 @@ The .NET Foundation licenses this file to you under the MIT license.
<NativeLibrary Include="@(NetCoreAppNativeLibrary->'%(EscapedPath)')" />
</ItemGroup>

<ItemGroup Condition="'$(StaticICULinking)' == 'true'">
<NativeLibrary Include="$(IntermediateOutputPath)/libs/System.Globalization.Native/build/libSystem.Globalization.Native.a"/>
<DirectPInvoke Include="libSystem.Globalization.Native" />
<StaticICULibs Include="-Wl,-Bstatic -licuio -licutu -licui18n -licuuc -licudata -Wl,-Bdynamic" />
</ItemGroup>

<ItemGroup Condition="'$(TargetOS)' == 'OSX'">
<NativeFramework Include="CoreFoundation" />
<NativeFramework Include="Foundation" />
<NativeFramework Include="Security" />
<NativeFramework Include="GSS" />
</ItemGroup>

<Exec Command="$(IlcHostPackagePath)/native/src/libs/System.Globalization.Native/local_build.sh $(IlcHostPackagePath)/ $(IntermediateOutputPath)" Condition="'$(StaticICULinking)' == 'true'"/>

<ItemGroup>
<LinkerArg Include="@(NativeLibrary)" />
<LinkerArg Include="--sysroot=$(SysRoot)" Condition="'$(SysRoot)' != ''" />
Expand All @@ -91,6 +99,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<LinkerArg Include="-lz" />
<LinkerArg Include="-lrt" Condition="'$(TargetOS)' != 'OSX'" />
<LinkerArg Include="-licucore" Condition="'$(TargetOS)' == 'OSX'" />
<LinkerArg Include="@(StaticICULibs)" Condition="'$(StaticICULinking)' == 'true'" />
<LinkerArg Include="-dynamiclib" Condition="'$(TargetOS)' == 'OSX' and '$(NativeLib)' == 'Shared'" />
<LinkerArg Include="-shared" Condition="'$(TargetOS)' != 'OSX' and '$(NativeLib)' == 'Shared'" />
<!-- binskim warning BA3001 PIE disabled on executable -->
Expand Down
21 changes: 21 additions & 0 deletions src/coreclr/nativeaot/docs/compiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,24 @@ You also need to specify the sysroot directory for Clang using the `SysRoot` pro
```

You may also follow [cross-building instructions](../../../../docs/workflow/building/coreclr/cross-building.md) to create your own sysroot directory.

## Using statically linked ICU
This feature can statically link libicu libraries (such as libicui18n.a) into your applications at build time.
NativeAOT binaries built with this feature can run even when libicu libraries are not installed.

You can use this feature by adding the `StaticICULinking` property to your project file as follows:

```xml
<PropertyGroup>
<StaticICULinking>true</StaticICULinking>
</PropertyGroup>
jkotas marked this conversation as resolved.
Show resolved Hide resolved
```

This feature is only supported on Linux.
smhmhmd marked this conversation as resolved.
Show resolved Hide resolved

### Prerequisites

Ubuntu (20.04+)
```
sudo apt-get install libicu-dev cmake
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<File Include="$(CoreCLRILCompilerDir)*" TargetPath="tools" />
<File Include="$(CoreCLRAotSdkDir)*" TargetPath="sdk" />
<File Include="$(MibcOptimizationDataDir)/$(TargetOS)/$(TargetArchitecture)/**/*.mibc" TargetPath="mibc" />
<File Include="$(MSBuildThisFileDirectory)\..\..\..\..\native\libs\System.Globalization.Native\*" TargetPath="native/src/libs/System.Globalization.Native"/>
smhmhmd marked this conversation as resolved.
Show resolved Hide resolved
<File Include="$(MSBuildThisFileDirectory)\..\..\..\..\native\minipal\*" TargetPath="native/src/minipal"/>
<File Include="$(MSBuildThisFileDirectory)\..\..\..\..\native\libs\Common\*" TargetPath="native/src/libs/Common"/>
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 13 additions & 1 deletion src/native/libs/System.Globalization.Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,21 @@ set(NATIVEGLOBALIZATION_SOURCES
pal_localeNumberData.c
pal_localeStringData.c
pal_normalization.c
pal_icushim.c
)

if (LOCAL_BUILD)
set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim_static.c)
add_definitions(-DLOCAL_BUILD)
add_definitions(-DSTATIC_ICU)
add_definitions(-DPALEXPORT=EXTERN_C)
add_definitions(-DTARGET_UNIX)
# For minipal files
include_directories(../../)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
else()
set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim.c)
endif()

if (CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_locale.m)
endif()
Expand Down
26 changes: 26 additions & 0 deletions src/native/libs/System.Globalization.Native/local_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

# Licensed to the .NET Foundation under one or more agreements.
# The .NET Foundation licenses this file to you under the MIT license.
#

# This script is used only for building libSystem.Globalization.Native.a
# in the end-user's computer for NativeAOT purposes (static linking).
# This file is not used during the dotnet runtime build.

# Currently, only Linux is supported

SHIM_SOURCE_DIR=$1/native/src
INTERMEDIATE_OUTPUT_PATH=$2

if [ -d "$SHIM_SOURCE_DIR" ]; then
LOCAL_SHIM_DIR="$INTERMEDIATE_OUTPUT_PATH"/libs/System.Globalization.Native/build
mkdir -p "$LOCAL_SHIM_DIR" && cd "$LOCAL_SHIM_DIR"
if [ $? -ne 0 ]; then echo "local_build.sh::ERROR: Cannot use local build directory"; exit 1; fi
cmake -S "$SHIM_SOURCE_DIR/libs/System.Globalization.Native/" -DLOCAL_BUILD:STRING=1 -DCLR_CMAKE_TARGET_UNIX:STRING=1
if [ $? -ne 0 ]; then echo "local_build.sh::ERROR: cmake failed"; exit 1; fi
make -j
if [ $? -ne 0 ]; then echo "local_build.sh::ERROR: Build failed"; exit 1; fi
fi

exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#include "pal_icushim_internal_android.h"
#else

#if !defined(LOCAL_BUILD)
#define U_DISABLE_RENAMING 1
#endif

// All ICU headers need to be included here so that all function prototypes are
// available before the function pointers are declared below.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,17 @@ const char* GlobalizationNative_GetICUDTName(const char* culture)

int32_t GlobalizationNative_LoadICU(void)
{
#if !defined(LOCAL_BUILD)
// Static NativeAOT compilation does not have
// GlobalizationNative_LoadICUData() as entrypoint
if (!isDataSet)
{
// don't try to locate icudt.dat automatically if mono_wasm_load_icu_data wasn't called
// and fallback to invariant mode
return 0;
}
#endif

UErrorCode status = 0;
UVersionInfo version;
// Request the CLDR version to perform basic ICU initialization and find out
Expand Down