From aed8b64b0a9fa38590b059308f936e1aede20b6f Mon Sep 17 00:00:00 2001 From: Samiullah Mohammed Date: Sun, 24 Jul 2022 23:26:33 +0000 Subject: [PATCH 01/17] Add local build for System.Globalization shim Bundle the System.Globalization.Native shim sources into the native AOT toolchain package and compile them automatically using C/C++ compiler on the target machine. Compiling of the shim sources using C/C++ compiler is done during dotnet publish as follows: dotnet publish /p:LocalSystemGlobalizationNative=1 -bl -r linux-x64 This change is 'opt-in', it is enabled only by using /p:LocalSystemGlobalizationNative=1 --- .../Microsoft.NETCore.Native.Unix.targets | 6 + .../Microsoft.DotNet.ILCompiler.pkgproj | 3 + .../CMakeLists-standalone.txt | 46 ++++++ .../config-standalone.h | 4 + .../System.Globalization.Native/pal_icushim.c | 12 ++ .../pal_icushim_native_static.c | 150 ++++++++++++++++++ .../pal_icushim_native_static.h | 2 + 7 files changed, 223 insertions(+) create mode 100644 src/native/libs/System.Globalization.Native/CMakeLists-standalone.txt create mode 100644 src/native/libs/System.Globalization.Native/config-standalone.h create mode 100644 src/native/libs/System.Globalization.Native/pal_icushim_native_static.c create mode 100644 src/native/libs/System.Globalization.Native/pal_icushim_native_static.h diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index ad6195b98cda0..dd0fe012bad85 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -64,7 +64,10 @@ The .NET Foundation licenses this file to you under the MIT license. $(IlcFrameworkNativePath)lib%(Identity).a + + + @@ -74,8 +77,11 @@ The .NET Foundation licenses this file to you under the MIT license. + + + diff --git a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj index 2dc56dde6c172..228aec8f20061 100644 --- a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj +++ b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj @@ -21,6 +21,9 @@ + + + diff --git a/src/native/libs/System.Globalization.Native/CMakeLists-standalone.txt b/src/native/libs/System.Globalization.Native/CMakeLists-standalone.txt new file mode 100644 index 0000000000000..2ac5d7378d0f1 --- /dev/null +++ b/src/native/libs/System.Globalization.Native/CMakeLists-standalone.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 3.6) + +project(System.Globalization.Native.User.Machine.Build C) + +include(configure.cmake) + +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") # Only Linux for now + +set(NATIVEGLOBALIZATION_SOURCES + pal_calendarData.c + pal_casing.c + pal_collation.c + pal_idna.c + pal_locale.c + pal_localeNumberData.c + pal_localeStringData.c + pal_normalization.c + pal_icushim.c + pal_icushim_native_static.c + pal_timeZoneInfo.c +) + +add_library(System.Globalization.Native-Static + STATIC + ${NATIVEGLOBALIZATION_SOURCES} +) + +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) + +# Workaround for https://unicode-org.atlassian.net/browse/ICU-20601 +add_compile_options(-Wno-extra-semi-stmt) +add_compile_options(-Wno-unknown-warning-option) + +add_definitions(-D_GNU_SOURCE -g -fPIC -DBUILDENV_DEBUG=1 -DDEBUG -DDISABLE_CONTRACTS -DHOST_64BIT -DHOST_AMD64 -DHOST_UNIX -DPALEXPORT=EXTERN_C -DTARGET_64BIT -DTARGET_AMD64 -DTARGET_LINUX -DTARGET_UNIX -DURTBLDENV_FRIENDLY=Debug -D_DBG -D_DEBUG -D_FILE_OFFSET_BITS=64 -DUSE_ICUSHIM_STATIC_BUILD -Wno-unused-variable) + +target_compile_options(System.Globalization.Native-Static PUBLIC -std=gnu99 -Wno-declaration-after-statement -D_GNU_SOURCE -g -fPIC -O0 -g -Wall -Wno-null-conversion -fno-omit-frame-pointer -fms-extensions -fwrapv -fstack-protector-strong -Werror) + +target_include_directories (System.Globalization.Native-Static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../Common ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../../) + +endif() diff --git a/src/native/libs/System.Globalization.Native/config-standalone.h b/src/native/libs/System.Globalization.Native/config-standalone.h new file mode 100644 index 0000000000000..8f5da9f65ad10 --- /dev/null +++ b/src/native/libs/System.Globalization.Native/config-standalone.h @@ -0,0 +1,4 @@ +#pragma once + +#define HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS 1 +#define HAVE_SET_MAX_VARIABLE 1 diff --git a/src/native/libs/System.Globalization.Native/pal_icushim.c b/src/native/libs/System.Globalization.Native/pal_icushim.c index d23499c80b1ee..8a59982b9c887 100644 --- a/src/native/libs/System.Globalization.Native/pal_icushim.c +++ b/src/native/libs/System.Globalization.Native/pal_icushim.c @@ -19,6 +19,10 @@ #include "pal_icushim.h" +#if defined(USE_ICUSHIM_STATIC_BUILD) +#include "pal_icushim_native_static.h" +#endif + // Define pointers to all the used ICU functions #define PER_FUNCTION_BLOCK(fn, lib, required) TYPEOF(fn)* fn##_ptr; FOR_ALL_ICU_FUNCTIONS @@ -481,6 +485,10 @@ int32_t GlobalizationNative_LoadICU() FOR_ALL_ICU_FUNCTIONS ValidateICUDataCanLoad(); +#if defined(USE_ICUSHIM_STATIC_BUILD) + InitWithStaticLibICUFunctions(); +#endif + InitializeVariableMaxAndTopPointers(symbolVersion); InitializeUColClonePointers(symbolVersion); @@ -538,6 +546,10 @@ void GlobalizationNative_InitICUFunctions(void* icuuc, void* icuin, const char* FOR_ALL_ICU_FUNCTIONS ValidateICUDataCanLoad(); +#if defined(USE_ICUSHIM_STATIC_BUILD) + InitWithStaticLibICUFunctions(); +#endif + InitializeVariableMaxAndTopPointers(symbolVersion); } diff --git a/src/native/libs/System.Globalization.Native/pal_icushim_native_static.c b/src/native/libs/System.Globalization.Native/pal_icushim_native_static.c new file mode 100644 index 0000000000000..fd8580a4e59ae --- /dev/null +++ b/src/native/libs/System.Globalization.Native/pal_icushim_native_static.c @@ -0,0 +1,150 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "pal_icushim_native_static.h" + +#define PER_FUNCTION_BLOCK(fn) __typeof(fn)* fn##_ptr = fn; + +// List of all functions from the ICU libraries that are used in the System.Globalization.Native.so +#define FOR_ALL_UNCONDITIONAL_STATIC_ICU_FUNCTIONS \ + PER_FUNCTION_BLOCK(u_charsToUChars) \ + PER_FUNCTION_BLOCK(u_getVersion) \ + PER_FUNCTION_BLOCK(u_strcmp) \ + PER_FUNCTION_BLOCK(u_strcpy) \ + PER_FUNCTION_BLOCK(u_strlen) \ + PER_FUNCTION_BLOCK(u_strncpy) \ + PER_FUNCTION_BLOCK(u_tolower) \ + PER_FUNCTION_BLOCK(u_toupper) \ + PER_FUNCTION_BLOCK(u_uastrncpy) \ + PER_FUNCTION_BLOCK(ubrk_close) \ + PER_FUNCTION_BLOCK(ubrk_openRules) \ + PER_FUNCTION_BLOCK(ucal_add) \ + PER_FUNCTION_BLOCK(ucal_close) \ + PER_FUNCTION_BLOCK(ucal_get) \ + PER_FUNCTION_BLOCK(ucal_getAttribute) \ + PER_FUNCTION_BLOCK(ucal_getKeywordValuesForLocale) \ + PER_FUNCTION_BLOCK(ucal_getLimit) \ + PER_FUNCTION_BLOCK(ucal_getNow) \ + PER_FUNCTION_BLOCK(ucal_getTimeZoneDisplayName) \ + PER_FUNCTION_BLOCK(ucal_open) \ + PER_FUNCTION_BLOCK(ucal_openTimeZoneIDEnumeration) \ + PER_FUNCTION_BLOCK(ucal_set) \ + PER_FUNCTION_BLOCK(ucal_setMillis) \ + PER_FUNCTION_BLOCK(ucol_close) \ + PER_FUNCTION_BLOCK(ucol_closeElements) \ + PER_FUNCTION_BLOCK(ucol_getOffset) \ + PER_FUNCTION_BLOCK(ucol_getRules) \ + PER_FUNCTION_BLOCK(ucol_getSortKey) \ + PER_FUNCTION_BLOCK(ucol_getStrength) \ + PER_FUNCTION_BLOCK(ucol_getVersion) \ + PER_FUNCTION_BLOCK(ucol_next) \ + PER_FUNCTION_BLOCK(ucol_previous) \ + PER_FUNCTION_BLOCK(ucol_open) \ + PER_FUNCTION_BLOCK(ucol_openElements) \ + PER_FUNCTION_BLOCK(ucol_openRules) \ + PER_FUNCTION_BLOCK(ucol_setAttribute) \ + PER_FUNCTION_BLOCK(ucol_strcoll) \ + PER_FUNCTION_BLOCK(udat_close) \ + PER_FUNCTION_BLOCK(udat_countSymbols) \ + PER_FUNCTION_BLOCK(udat_format) \ + PER_FUNCTION_BLOCK(udat_getSymbols) \ + PER_FUNCTION_BLOCK(udat_open) \ + PER_FUNCTION_BLOCK(udat_setCalendar) \ + PER_FUNCTION_BLOCK(udat_toPattern) \ + PER_FUNCTION_BLOCK(udatpg_close) \ + PER_FUNCTION_BLOCK(udatpg_getBestPattern) \ + PER_FUNCTION_BLOCK(udatpg_open) \ + PER_FUNCTION_BLOCK(uenum_close) \ + PER_FUNCTION_BLOCK(uenum_count) \ + PER_FUNCTION_BLOCK(uenum_next) \ + PER_FUNCTION_BLOCK(uidna_close) \ + PER_FUNCTION_BLOCK(uidna_nameToASCII) \ + PER_FUNCTION_BLOCK(uidna_nameToUnicode) \ + PER_FUNCTION_BLOCK(uidna_openUTS46) \ + PER_FUNCTION_BLOCK(uloc_canonicalize) \ + PER_FUNCTION_BLOCK(uloc_countAvailable) \ + PER_FUNCTION_BLOCK(uloc_getAvailable) \ + PER_FUNCTION_BLOCK(uloc_getBaseName) \ + PER_FUNCTION_BLOCK(uloc_getCharacterOrientation) \ + PER_FUNCTION_BLOCK(uloc_getCountry) \ + PER_FUNCTION_BLOCK(uloc_getDefault) \ + PER_FUNCTION_BLOCK(uloc_getDisplayCountry) \ + PER_FUNCTION_BLOCK(uloc_getDisplayLanguage) \ + PER_FUNCTION_BLOCK(uloc_getDisplayName) \ + PER_FUNCTION_BLOCK(uloc_getISO3Country) \ + PER_FUNCTION_BLOCK(uloc_getISO3Language) \ + PER_FUNCTION_BLOCK(uloc_getKeywordValue) \ + PER_FUNCTION_BLOCK(uloc_getLanguage) \ + PER_FUNCTION_BLOCK(uloc_getLCID) \ + PER_FUNCTION_BLOCK(uloc_getName) \ + PER_FUNCTION_BLOCK(uloc_getParent) \ + PER_FUNCTION_BLOCK(uloc_setKeywordValue) \ + PER_FUNCTION_BLOCK(ulocdata_getCLDRVersion) \ + PER_FUNCTION_BLOCK(ulocdata_getMeasurementSystem) \ + PER_FUNCTION_BLOCK(unorm2_getNFCInstance) \ + PER_FUNCTION_BLOCK(unorm2_getNFDInstance) \ + PER_FUNCTION_BLOCK(unorm2_getNFKCInstance) \ + PER_FUNCTION_BLOCK(unorm2_getNFKDInstance) \ + PER_FUNCTION_BLOCK(unorm2_isNormalized) \ + PER_FUNCTION_BLOCK(unorm2_normalize) \ + PER_FUNCTION_BLOCK(unum_close) \ + PER_FUNCTION_BLOCK(unum_getAttribute) \ + PER_FUNCTION_BLOCK(unum_getSymbol) \ + PER_FUNCTION_BLOCK(unum_open) \ + PER_FUNCTION_BLOCK(unum_toPattern) \ + PER_FUNCTION_BLOCK(ures_close) \ + PER_FUNCTION_BLOCK(ures_getByKey) \ + PER_FUNCTION_BLOCK(ures_getSize) \ + PER_FUNCTION_BLOCK(ures_getStringByIndex) \ + PER_FUNCTION_BLOCK(ures_open) \ + PER_FUNCTION_BLOCK(usearch_close) \ + PER_FUNCTION_BLOCK(usearch_first) \ + PER_FUNCTION_BLOCK(usearch_getBreakIterator) \ + PER_FUNCTION_BLOCK(usearch_getMatchedLength) \ + PER_FUNCTION_BLOCK(usearch_last) \ + PER_FUNCTION_BLOCK(usearch_openFromCollator) \ + PER_FUNCTION_BLOCK(usearch_setPattern) \ + PER_FUNCTION_BLOCK(usearch_setText) + +#define FOR_ALL_OS_CONDITIONAL_STATIC_ICU_FUNCTIONS \ + PER_FUNCTION_BLOCK(ucurr_forLocale) \ + PER_FUNCTION_BLOCK(ucurr_getName) \ + PER_FUNCTION_BLOCK(uldn_close) \ + PER_FUNCTION_BLOCK(uldn_keyValueDisplayName) \ + PER_FUNCTION_BLOCK(uldn_open) + +// The following are the list of the ICU APIs which are optional. If these APIs exist in the ICU version we load at runtime, then we'll use it. +// Otherwise, we'll just not provide the functionality to users which needed these APIs. +#define FOR_ALL_OPTIONAL_STATIC_ICU_FUNCTIONS \ + PER_FUNCTION_BLOCK(ucal_getWindowsTimeZoneID) \ + PER_FUNCTION_BLOCK(ucal_getTimeZoneIDForWindowsID) \ + PER_FUNCTION_BLOCK(ucol_setMaxVariable) + +// ucol_setVariableTop is deprecated +// ucol_safeClone is deprecated + +#define FOR_ALL_STATIC_ICU_FUNCTIONS \ + FOR_ALL_UNCONDITIONAL_STATIC_ICU_FUNCTIONS \ + FOR_ALL_OPTIONAL_STATIC_ICU_FUNCTIONS \ + FOR_ALL_OS_CONDITIONAL_STATIC_ICU_FUNCTIONS + +void InitWithStaticLibICUFunctions() +{ + FOR_ALL_STATIC_ICU_FUNCTIONS +} diff --git a/src/native/libs/System.Globalization.Native/pal_icushim_native_static.h b/src/native/libs/System.Globalization.Native/pal_icushim_native_static.h new file mode 100644 index 0000000000000..d3b9ea5fc0499 --- /dev/null +++ b/src/native/libs/System.Globalization.Native/pal_icushim_native_static.h @@ -0,0 +1,2 @@ + +void InitWithStaticLibICUFunctions(void); From f2fa736ae51872c24a3cabb50032187810eee068 Mon Sep 17 00:00:00 2001 From: Samiullah Mohammed Date: Mon, 1 Aug 2022 18:12:34 -0700 Subject: [PATCH 02/17] Incorporate review feedback * Copy shim source code into users Obj directory at IntermediateOutputPath and compile ** $ ls -al obj/Debug/net7.0/linux-x64/shim_source_code/libs/System.Globalization.Native/build/libSystem.Globalization.Native-Static.a * Add shell script for readability * Add copyright headers --- .../Microsoft.NETCore.Native.Unix.targets | 7 ++-- .../build-nativeaot-shim-standalone.sh | 36 +++++++++++++++++++ .../config-standalone.h | 4 +++ .../pal_icushim_native_static.c | 5 ++- .../pal_icushim_native_static.h | 3 ++ 5 files changed, 50 insertions(+), 5 deletions(-) create mode 100755 src/native/libs/System.Globalization.Native/build-nativeaot-shim-standalone.sh diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index dd0fe012bad85..57097733a07e6 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -64,10 +64,9 @@ The .NET Foundation licenses this file to you under the MIT license. $(IlcFrameworkNativePath)lib%(Identity).a - + - - + @@ -77,7 +76,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + diff --git a/src/native/libs/System.Globalization.Native/build-nativeaot-shim-standalone.sh b/src/native/libs/System.Globalization.Native/build-nativeaot-shim-standalone.sh new file mode 100755 index 0000000000000..619c7fea61f2c --- /dev/null +++ b/src/native/libs/System.Globalization.Native/build-nativeaot-shim-standalone.sh @@ -0,0 +1,36 @@ +#!/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). +# It is not used during the dotnet runtime build. + +# Currently, only Linux is supported + +SHIM_SOURCE_DIR=$1/shim_source_code +INTERMEDIATE_OUTPUT_PATH=$2 + +if [ -d "$SHIM_SOURCE_DIR" ]; then + cp -r "$SHIM_SOURCE_DIR" "$INTERMEDIATE_OUTPUT_PATH" + if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Cannot copy into $INTERMEDIATE_OUTPUT_PATH"; exit 1; fi + LOCAL_SHIM_DIR="$INTERMEDIATE_OUTPUT_PATH"/shim_source_code/libs/System.Globalization.Native + cd "$LOCAL_SHIM_DIR" + if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Cannot cd into $LOCAL_SHIM_DIR"; exit 1; fi + cp CMakeLists-standalone.txt CMakeLists.txt + if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Cannot copy CMakeLists.txt"; exit 1; fi + cp config-standalone.h config.h + if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Cannot copy config.h"; exit 1; fi + mkdir -p build + if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Cannot mkdir build directory"; exit 1; fi + cd build + if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Build directory does not exist"; exit 1; fi + cmake ../ + if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: cmake failed"; exit 1; fi + make -j; + if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Build failed"; exit 1; fi +fi + +exit 0 diff --git a/src/native/libs/System.Globalization.Native/config-standalone.h b/src/native/libs/System.Globalization.Native/config-standalone.h index 8f5da9f65ad10..f2ebbe3c0018e 100644 --- a/src/native/libs/System.Globalization.Native/config-standalone.h +++ b/src/native/libs/System.Globalization.Native/config-standalone.h @@ -1,3 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + #pragma once #define HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS 1 diff --git a/src/native/libs/System.Globalization.Native/pal_icushim_native_static.c b/src/native/libs/System.Globalization.Native/pal_icushim_native_static.c index fd8580a4e59ae..283795ad6b398 100644 --- a/src/native/libs/System.Globalization.Native/pal_icushim_native_static.c +++ b/src/native/libs/System.Globalization.Native/pal_icushim_native_static.c @@ -1,4 +1,7 @@ -#include +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + #include #include #include diff --git a/src/native/libs/System.Globalization.Native/pal_icushim_native_static.h b/src/native/libs/System.Globalization.Native/pal_icushim_native_static.h index d3b9ea5fc0499..cc046e2a53602 100644 --- a/src/native/libs/System.Globalization.Native/pal_icushim_native_static.h +++ b/src/native/libs/System.Globalization.Native/pal_icushim_native_static.h @@ -1,2 +1,5 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// void InitWithStaticLibICUFunctions(void); From d8dabf2cf8e1e97964eba4fc83ce497b4d3c7765 Mon Sep 17 00:00:00 2001 From: Samiullah Mohammed Date: Mon, 1 Aug 2022 18:23:09 -0700 Subject: [PATCH 03/17] Fix IlCompilerPackagePath Add change that was part of previous commit --- .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 57097733a07e6..7e66064898451 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -76,6 +76,11 @@ The .NET Foundation licenses this file to you under the MIT license. + + + + + From e5484155869d11be1bc13b71a6689e3821f46d39 Mon Sep 17 00:00:00 2001 From: Samiullah Mohammed Date: Tue, 2 Aug 2022 13:59:38 -0700 Subject: [PATCH 04/17] Address review feedback * Include existing pal_icushim_static.c by using STATIC_ICU define * Use IlcSdkPath to copy shim source code --- .../Microsoft.NETCore.Native.Unix.targets | 7 +- .../CMakeLists-standalone.txt | 7 +- .../System.Globalization.Native/pal_icushim.c | 8 - .../pal_icushim_internal.h | 2 + .../pal_icushim_native_static.c | 153 ------------------ .../pal_icushim_native_static.h | 5 - .../pal_icushim_static.c | 5 + 7 files changed, 11 insertions(+), 176 deletions(-) delete mode 100644 src/native/libs/System.Globalization.Native/pal_icushim_native_static.c delete mode 100644 src/native/libs/System.Globalization.Native/pal_icushim_native_static.h diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 7e66064898451..660c0b2349db1 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -76,12 +76,7 @@ The .NET Foundation licenses this file to you under the MIT license. - - - - - - + diff --git a/src/native/libs/System.Globalization.Native/CMakeLists-standalone.txt b/src/native/libs/System.Globalization.Native/CMakeLists-standalone.txt index 2ac5d7378d0f1..685823ff03f6c 100644 --- a/src/native/libs/System.Globalization.Native/CMakeLists-standalone.txt +++ b/src/native/libs/System.Globalization.Native/CMakeLists-standalone.txt @@ -15,8 +15,7 @@ set(NATIVEGLOBALIZATION_SOURCES pal_localeNumberData.c pal_localeStringData.c pal_normalization.c - pal_icushim.c - pal_icushim_native_static.c + pal_icushim_static.c pal_timeZoneInfo.c ) @@ -37,9 +36,9 @@ add_compile_options(-Wno-documentation-unknown-command) add_compile_options(-Wno-extra-semi-stmt) add_compile_options(-Wno-unknown-warning-option) -add_definitions(-D_GNU_SOURCE -g -fPIC -DBUILDENV_DEBUG=1 -DDEBUG -DDISABLE_CONTRACTS -DHOST_64BIT -DHOST_AMD64 -DHOST_UNIX -DPALEXPORT=EXTERN_C -DTARGET_64BIT -DTARGET_AMD64 -DTARGET_LINUX -DTARGET_UNIX -DURTBLDENV_FRIENDLY=Debug -D_DBG -D_DEBUG -D_FILE_OFFSET_BITS=64 -DUSE_ICUSHIM_STATIC_BUILD -Wno-unused-variable) +add_definitions(-D_GNU_SOURCE -g -fPIC -DBUILDENV_DEBUG=1 -DDEBUG -DDISABLE_CONTRACTS -DHOST_64BIT -DHOST_AMD64 -DHOST_UNIX -DPALEXPORT=EXTERN_C -DTARGET_64BIT -DTARGET_AMD64 -DTARGET_LINUX -DTARGET_UNIX -DURTBLDENV_FRIENDLY=Debug -D_DBG -D_DEBUG -D_FILE_OFFSET_BITS=64 -DSTATIC_ICU -DSTATIC_SHIM_COMPILE) -target_compile_options(System.Globalization.Native-Static PUBLIC -std=gnu99 -Wno-declaration-after-statement -D_GNU_SOURCE -g -fPIC -O0 -g -Wall -Wno-null-conversion -fno-omit-frame-pointer -fms-extensions -fwrapv -fstack-protector-strong -Werror) +target_compile_options(System.Globalization.Native-Static PUBLIC -std=gnu99 -Wno-declaration-after-statement -D_GNU_SOURCE -g -fPIC -O0 -g -Wall -fno-omit-frame-pointer -fms-extensions -fwrapv -fstack-protector-strong) target_include_directories (System.Globalization.Native-Static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../Common ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../../) diff --git a/src/native/libs/System.Globalization.Native/pal_icushim.c b/src/native/libs/System.Globalization.Native/pal_icushim.c index 8a59982b9c887..0da0565de1f6e 100644 --- a/src/native/libs/System.Globalization.Native/pal_icushim.c +++ b/src/native/libs/System.Globalization.Native/pal_icushim.c @@ -19,10 +19,6 @@ #include "pal_icushim.h" -#if defined(USE_ICUSHIM_STATIC_BUILD) -#include "pal_icushim_native_static.h" -#endif - // Define pointers to all the used ICU functions #define PER_FUNCTION_BLOCK(fn, lib, required) TYPEOF(fn)* fn##_ptr; FOR_ALL_ICU_FUNCTIONS @@ -546,10 +542,6 @@ void GlobalizationNative_InitICUFunctions(void* icuuc, void* icuin, const char* FOR_ALL_ICU_FUNCTIONS ValidateICUDataCanLoad(); -#if defined(USE_ICUSHIM_STATIC_BUILD) - InitWithStaticLibICUFunctions(); -#endif - InitializeVariableMaxAndTopPointers(symbolVersion); } diff --git a/src/native/libs/System.Globalization.Native/pal_icushim_internal.h b/src/native/libs/System.Globalization.Native/pal_icushim_internal.h index f01ef2384c3c5..4545af0ef96c0 100644 --- a/src/native/libs/System.Globalization.Native/pal_icushim_internal.h +++ b/src/native/libs/System.Globalization.Native/pal_icushim_internal.h @@ -15,7 +15,9 @@ #include "pal_icushim_internal_android.h" #else +#if !defined(STATIC_SHIM_COMPILE) #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. diff --git a/src/native/libs/System.Globalization.Native/pal_icushim_native_static.c b/src/native/libs/System.Globalization.Native/pal_icushim_native_static.c deleted file mode 100644 index 283795ad6b398..0000000000000 --- a/src/native/libs/System.Globalization.Native/pal_icushim_native_static.c +++ /dev/null @@ -1,153 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "pal_icushim_native_static.h" - -#define PER_FUNCTION_BLOCK(fn) __typeof(fn)* fn##_ptr = fn; - -// List of all functions from the ICU libraries that are used in the System.Globalization.Native.so -#define FOR_ALL_UNCONDITIONAL_STATIC_ICU_FUNCTIONS \ - PER_FUNCTION_BLOCK(u_charsToUChars) \ - PER_FUNCTION_BLOCK(u_getVersion) \ - PER_FUNCTION_BLOCK(u_strcmp) \ - PER_FUNCTION_BLOCK(u_strcpy) \ - PER_FUNCTION_BLOCK(u_strlen) \ - PER_FUNCTION_BLOCK(u_strncpy) \ - PER_FUNCTION_BLOCK(u_tolower) \ - PER_FUNCTION_BLOCK(u_toupper) \ - PER_FUNCTION_BLOCK(u_uastrncpy) \ - PER_FUNCTION_BLOCK(ubrk_close) \ - PER_FUNCTION_BLOCK(ubrk_openRules) \ - PER_FUNCTION_BLOCK(ucal_add) \ - PER_FUNCTION_BLOCK(ucal_close) \ - PER_FUNCTION_BLOCK(ucal_get) \ - PER_FUNCTION_BLOCK(ucal_getAttribute) \ - PER_FUNCTION_BLOCK(ucal_getKeywordValuesForLocale) \ - PER_FUNCTION_BLOCK(ucal_getLimit) \ - PER_FUNCTION_BLOCK(ucal_getNow) \ - PER_FUNCTION_BLOCK(ucal_getTimeZoneDisplayName) \ - PER_FUNCTION_BLOCK(ucal_open) \ - PER_FUNCTION_BLOCK(ucal_openTimeZoneIDEnumeration) \ - PER_FUNCTION_BLOCK(ucal_set) \ - PER_FUNCTION_BLOCK(ucal_setMillis) \ - PER_FUNCTION_BLOCK(ucol_close) \ - PER_FUNCTION_BLOCK(ucol_closeElements) \ - PER_FUNCTION_BLOCK(ucol_getOffset) \ - PER_FUNCTION_BLOCK(ucol_getRules) \ - PER_FUNCTION_BLOCK(ucol_getSortKey) \ - PER_FUNCTION_BLOCK(ucol_getStrength) \ - PER_FUNCTION_BLOCK(ucol_getVersion) \ - PER_FUNCTION_BLOCK(ucol_next) \ - PER_FUNCTION_BLOCK(ucol_previous) \ - PER_FUNCTION_BLOCK(ucol_open) \ - PER_FUNCTION_BLOCK(ucol_openElements) \ - PER_FUNCTION_BLOCK(ucol_openRules) \ - PER_FUNCTION_BLOCK(ucol_setAttribute) \ - PER_FUNCTION_BLOCK(ucol_strcoll) \ - PER_FUNCTION_BLOCK(udat_close) \ - PER_FUNCTION_BLOCK(udat_countSymbols) \ - PER_FUNCTION_BLOCK(udat_format) \ - PER_FUNCTION_BLOCK(udat_getSymbols) \ - PER_FUNCTION_BLOCK(udat_open) \ - PER_FUNCTION_BLOCK(udat_setCalendar) \ - PER_FUNCTION_BLOCK(udat_toPattern) \ - PER_FUNCTION_BLOCK(udatpg_close) \ - PER_FUNCTION_BLOCK(udatpg_getBestPattern) \ - PER_FUNCTION_BLOCK(udatpg_open) \ - PER_FUNCTION_BLOCK(uenum_close) \ - PER_FUNCTION_BLOCK(uenum_count) \ - PER_FUNCTION_BLOCK(uenum_next) \ - PER_FUNCTION_BLOCK(uidna_close) \ - PER_FUNCTION_BLOCK(uidna_nameToASCII) \ - PER_FUNCTION_BLOCK(uidna_nameToUnicode) \ - PER_FUNCTION_BLOCK(uidna_openUTS46) \ - PER_FUNCTION_BLOCK(uloc_canonicalize) \ - PER_FUNCTION_BLOCK(uloc_countAvailable) \ - PER_FUNCTION_BLOCK(uloc_getAvailable) \ - PER_FUNCTION_BLOCK(uloc_getBaseName) \ - PER_FUNCTION_BLOCK(uloc_getCharacterOrientation) \ - PER_FUNCTION_BLOCK(uloc_getCountry) \ - PER_FUNCTION_BLOCK(uloc_getDefault) \ - PER_FUNCTION_BLOCK(uloc_getDisplayCountry) \ - PER_FUNCTION_BLOCK(uloc_getDisplayLanguage) \ - PER_FUNCTION_BLOCK(uloc_getDisplayName) \ - PER_FUNCTION_BLOCK(uloc_getISO3Country) \ - PER_FUNCTION_BLOCK(uloc_getISO3Language) \ - PER_FUNCTION_BLOCK(uloc_getKeywordValue) \ - PER_FUNCTION_BLOCK(uloc_getLanguage) \ - PER_FUNCTION_BLOCK(uloc_getLCID) \ - PER_FUNCTION_BLOCK(uloc_getName) \ - PER_FUNCTION_BLOCK(uloc_getParent) \ - PER_FUNCTION_BLOCK(uloc_setKeywordValue) \ - PER_FUNCTION_BLOCK(ulocdata_getCLDRVersion) \ - PER_FUNCTION_BLOCK(ulocdata_getMeasurementSystem) \ - PER_FUNCTION_BLOCK(unorm2_getNFCInstance) \ - PER_FUNCTION_BLOCK(unorm2_getNFDInstance) \ - PER_FUNCTION_BLOCK(unorm2_getNFKCInstance) \ - PER_FUNCTION_BLOCK(unorm2_getNFKDInstance) \ - PER_FUNCTION_BLOCK(unorm2_isNormalized) \ - PER_FUNCTION_BLOCK(unorm2_normalize) \ - PER_FUNCTION_BLOCK(unum_close) \ - PER_FUNCTION_BLOCK(unum_getAttribute) \ - PER_FUNCTION_BLOCK(unum_getSymbol) \ - PER_FUNCTION_BLOCK(unum_open) \ - PER_FUNCTION_BLOCK(unum_toPattern) \ - PER_FUNCTION_BLOCK(ures_close) \ - PER_FUNCTION_BLOCK(ures_getByKey) \ - PER_FUNCTION_BLOCK(ures_getSize) \ - PER_FUNCTION_BLOCK(ures_getStringByIndex) \ - PER_FUNCTION_BLOCK(ures_open) \ - PER_FUNCTION_BLOCK(usearch_close) \ - PER_FUNCTION_BLOCK(usearch_first) \ - PER_FUNCTION_BLOCK(usearch_getBreakIterator) \ - PER_FUNCTION_BLOCK(usearch_getMatchedLength) \ - PER_FUNCTION_BLOCK(usearch_last) \ - PER_FUNCTION_BLOCK(usearch_openFromCollator) \ - PER_FUNCTION_BLOCK(usearch_setPattern) \ - PER_FUNCTION_BLOCK(usearch_setText) - -#define FOR_ALL_OS_CONDITIONAL_STATIC_ICU_FUNCTIONS \ - PER_FUNCTION_BLOCK(ucurr_forLocale) \ - PER_FUNCTION_BLOCK(ucurr_getName) \ - PER_FUNCTION_BLOCK(uldn_close) \ - PER_FUNCTION_BLOCK(uldn_keyValueDisplayName) \ - PER_FUNCTION_BLOCK(uldn_open) - -// The following are the list of the ICU APIs which are optional. If these APIs exist in the ICU version we load at runtime, then we'll use it. -// Otherwise, we'll just not provide the functionality to users which needed these APIs. -#define FOR_ALL_OPTIONAL_STATIC_ICU_FUNCTIONS \ - PER_FUNCTION_BLOCK(ucal_getWindowsTimeZoneID) \ - PER_FUNCTION_BLOCK(ucal_getTimeZoneIDForWindowsID) \ - PER_FUNCTION_BLOCK(ucol_setMaxVariable) - -// ucol_setVariableTop is deprecated -// ucol_safeClone is deprecated - -#define FOR_ALL_STATIC_ICU_FUNCTIONS \ - FOR_ALL_UNCONDITIONAL_STATIC_ICU_FUNCTIONS \ - FOR_ALL_OPTIONAL_STATIC_ICU_FUNCTIONS \ - FOR_ALL_OS_CONDITIONAL_STATIC_ICU_FUNCTIONS - -void InitWithStaticLibICUFunctions() -{ - FOR_ALL_STATIC_ICU_FUNCTIONS -} diff --git a/src/native/libs/System.Globalization.Native/pal_icushim_native_static.h b/src/native/libs/System.Globalization.Native/pal_icushim_native_static.h deleted file mode 100644 index cc046e2a53602..0000000000000 --- a/src/native/libs/System.Globalization.Native/pal_icushim_native_static.h +++ /dev/null @@ -1,5 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -void InitWithStaticLibICUFunctions(void); diff --git a/src/native/libs/System.Globalization.Native/pal_icushim_static.c b/src/native/libs/System.Globalization.Native/pal_icushim_static.c index ff762fc4c6ab2..288355b585691 100644 --- a/src/native/libs/System.Globalization.Native/pal_icushim_static.c +++ b/src/native/libs/System.Globalization.Native/pal_icushim_static.c @@ -217,12 +217,17 @@ const char* GlobalizationNative_GetICUDTName(const char* culture) int32_t GlobalizationNative_LoadICU(void) { +#if !defined(STATIC_SHIM_COMPILE) +// 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 From 6075e0316bb34a1f0629a18b2cb3481a9ba2de77 Mon Sep 17 00:00:00 2001 From: Samiullah Mohammed Date: Thu, 4 Aug 2022 11:17:10 -0700 Subject: [PATCH 05/17] Incorporate review feedback * Remove USE_ICUSHIM_STATIC_BUILD in pal_icushim.c * Rename shim_source_code to source_code in Microsoft.DotNet.ILCompiler.pkgproj and script * Regular config is used, config-standalone.h is removed * IlcPath/.. is replaced to make the ".." go away --- .../Microsoft.NETCore.Native.Unix.targets | 9 +++++++-- .../Microsoft.DotNet.ILCompiler.pkgproj | 6 +++--- .../CMakeLists-standalone.txt | 2 +- .../build-nativeaot-shim-standalone.sh | 6 ++---- .../libs/System.Globalization.Native/config-standalone.h | 8 -------- .../libs/System.Globalization.Native/pal_icushim.c | 4 ---- 6 files changed, 13 insertions(+), 22 deletions(-) delete mode 100644 src/native/libs/System.Globalization.Native/config-standalone.h diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 660c0b2349db1..2be142dba09ca 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -64,7 +64,7 @@ The .NET Foundation licenses this file to you under the MIT license. $(IlcFrameworkNativePath)lib%(Identity).a - + @@ -76,7 +76,12 @@ The .NET Foundation licenses this file to you under the MIT license. - + + + + + + diff --git a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj index 228aec8f20061..cee0d48f61841 100644 --- a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj +++ b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj @@ -21,9 +21,9 @@ - - - + + + diff --git a/src/native/libs/System.Globalization.Native/CMakeLists-standalone.txt b/src/native/libs/System.Globalization.Native/CMakeLists-standalone.txt index 685823ff03f6c..a643067b82df9 100644 --- a/src/native/libs/System.Globalization.Native/CMakeLists-standalone.txt +++ b/src/native/libs/System.Globalization.Native/CMakeLists-standalone.txt @@ -40,6 +40,6 @@ add_definitions(-D_GNU_SOURCE -g -fPIC -DBUILDENV_DEBUG=1 -DDEBUG -DDISABLE_CONT target_compile_options(System.Globalization.Native-Static PUBLIC -std=gnu99 -Wno-declaration-after-statement -D_GNU_SOURCE -g -fPIC -O0 -g -Wall -fno-omit-frame-pointer -fms-extensions -fwrapv -fstack-protector-strong) -target_include_directories (System.Globalization.Native-Static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../Common ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../../) +target_include_directories (System.Globalization.Native-Static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../Common ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../../ ${CMAKE_CURRENT_SOURCE_DIR}/build) endif() diff --git a/src/native/libs/System.Globalization.Native/build-nativeaot-shim-standalone.sh b/src/native/libs/System.Globalization.Native/build-nativeaot-shim-standalone.sh index 619c7fea61f2c..636da341f7f2f 100755 --- a/src/native/libs/System.Globalization.Native/build-nativeaot-shim-standalone.sh +++ b/src/native/libs/System.Globalization.Native/build-nativeaot-shim-standalone.sh @@ -10,19 +10,17 @@ # Currently, only Linux is supported -SHIM_SOURCE_DIR=$1/shim_source_code +SHIM_SOURCE_DIR=$1/source_code INTERMEDIATE_OUTPUT_PATH=$2 if [ -d "$SHIM_SOURCE_DIR" ]; then cp -r "$SHIM_SOURCE_DIR" "$INTERMEDIATE_OUTPUT_PATH" if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Cannot copy into $INTERMEDIATE_OUTPUT_PATH"; exit 1; fi - LOCAL_SHIM_DIR="$INTERMEDIATE_OUTPUT_PATH"/shim_source_code/libs/System.Globalization.Native + LOCAL_SHIM_DIR="$INTERMEDIATE_OUTPUT_PATH"/source_code/libs/System.Globalization.Native cd "$LOCAL_SHIM_DIR" if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Cannot cd into $LOCAL_SHIM_DIR"; exit 1; fi cp CMakeLists-standalone.txt CMakeLists.txt if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Cannot copy CMakeLists.txt"; exit 1; fi - cp config-standalone.h config.h - if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Cannot copy config.h"; exit 1; fi mkdir -p build if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Cannot mkdir build directory"; exit 1; fi cd build diff --git a/src/native/libs/System.Globalization.Native/config-standalone.h b/src/native/libs/System.Globalization.Native/config-standalone.h deleted file mode 100644 index f2ebbe3c0018e..0000000000000 --- a/src/native/libs/System.Globalization.Native/config-standalone.h +++ /dev/null @@ -1,8 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -#pragma once - -#define HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS 1 -#define HAVE_SET_MAX_VARIABLE 1 diff --git a/src/native/libs/System.Globalization.Native/pal_icushim.c b/src/native/libs/System.Globalization.Native/pal_icushim.c index 0da0565de1f6e..d23499c80b1ee 100644 --- a/src/native/libs/System.Globalization.Native/pal_icushim.c +++ b/src/native/libs/System.Globalization.Native/pal_icushim.c @@ -481,10 +481,6 @@ int32_t GlobalizationNative_LoadICU() FOR_ALL_ICU_FUNCTIONS ValidateICUDataCanLoad(); -#if defined(USE_ICUSHIM_STATIC_BUILD) - InitWithStaticLibICUFunctions(); -#endif - InitializeVariableMaxAndTopPointers(symbolVersion); InitializeUColClonePointers(symbolVersion); From 3fcba3dfa90bf597fffd1b83f2e85d619fde851b Mon Sep 17 00:00:00 2001 From: smhmhmd Date: Mon, 8 Aug 2022 19:19:47 +0000 Subject: [PATCH 06/17] Address feedback from 08/04 * Rename option to ICUStaticLinking * Remove static-build/CMakeLists.txt} (59%) create mode 100755 src/native/libs/System.Globalization.Native/static-build/build-nativeaot-shim-standalone.sh diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 2be142dba09ca..d2dbbbd531495 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -64,9 +64,9 @@ The .NET Foundation licenses this file to you under the MIT license. $(IlcFrameworkNativePath)lib%(Identity).a - + - + @@ -76,16 +76,10 @@ The .NET Foundation licenses this file to you under the MIT license. - - - - - - + - @@ -100,6 +94,7 @@ The .NET Foundation licenses this file to you under the MIT license. + diff --git a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj index cee0d48f61841..14c453e6ac363 100644 --- a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj +++ b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj @@ -22,6 +22,7 @@ + diff --git a/src/native/libs/System.Globalization.Native/build-nativeaot-shim-standalone.sh b/src/native/libs/System.Globalization.Native/build-nativeaot-shim-standalone.sh deleted file mode 100755 index 636da341f7f2f..0000000000000 --- a/src/native/libs/System.Globalization.Native/build-nativeaot-shim-standalone.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/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). -# It is not used during the dotnet runtime build. - -# Currently, only Linux is supported - -SHIM_SOURCE_DIR=$1/source_code -INTERMEDIATE_OUTPUT_PATH=$2 - -if [ -d "$SHIM_SOURCE_DIR" ]; then - cp -r "$SHIM_SOURCE_DIR" "$INTERMEDIATE_OUTPUT_PATH" - if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Cannot copy into $INTERMEDIATE_OUTPUT_PATH"; exit 1; fi - LOCAL_SHIM_DIR="$INTERMEDIATE_OUTPUT_PATH"/source_code/libs/System.Globalization.Native - cd "$LOCAL_SHIM_DIR" - if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Cannot cd into $LOCAL_SHIM_DIR"; exit 1; fi - cp CMakeLists-standalone.txt CMakeLists.txt - if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Cannot copy CMakeLists.txt"; exit 1; fi - mkdir -p build - if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Cannot mkdir build directory"; exit 1; fi - cd build - if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Build directory does not exist"; exit 1; fi - cmake ../ - if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: cmake failed"; exit 1; fi - make -j; - if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Build failed"; exit 1; fi -fi - -exit 0 diff --git a/src/native/libs/System.Globalization.Native/CMakeLists-standalone.txt b/src/native/libs/System.Globalization.Native/static-build/CMakeLists.txt similarity index 59% rename from src/native/libs/System.Globalization.Native/CMakeLists-standalone.txt rename to src/native/libs/System.Globalization.Native/static-build/CMakeLists.txt index a643067b82df9..4206d7367d04d 100644 --- a/src/native/libs/System.Globalization.Native/CMakeLists-standalone.txt +++ b/src/native/libs/System.Globalization.Native/static-build/CMakeLists.txt @@ -2,21 +2,21 @@ cmake_minimum_required(VERSION 3.6) project(System.Globalization.Native.User.Machine.Build C) -include(configure.cmake) - if(CMAKE_SYSTEM_NAME STREQUAL "Linux") # Only Linux for now +configure_file(../config.h.in config.h) + set(NATIVEGLOBALIZATION_SOURCES - pal_calendarData.c - pal_casing.c - pal_collation.c - pal_idna.c - pal_locale.c - pal_localeNumberData.c - pal_localeStringData.c - pal_normalization.c - pal_icushim_static.c - pal_timeZoneInfo.c + ../pal_calendarData.c + ../pal_casing.c + ../pal_collation.c + ../pal_idna.c + ../pal_locale.c + ../pal_localeNumberData.c + ../pal_localeStringData.c + ../pal_normalization.c + ../pal_icushim_static.c + ../pal_timeZoneInfo.c ) add_library(System.Globalization.Native-Static @@ -36,10 +36,12 @@ add_compile_options(-Wno-documentation-unknown-command) add_compile_options(-Wno-extra-semi-stmt) add_compile_options(-Wno-unknown-warning-option) -add_definitions(-D_GNU_SOURCE -g -fPIC -DBUILDENV_DEBUG=1 -DDEBUG -DDISABLE_CONTRACTS -DHOST_64BIT -DHOST_AMD64 -DHOST_UNIX -DPALEXPORT=EXTERN_C -DTARGET_64BIT -DTARGET_AMD64 -DTARGET_LINUX -DTARGET_UNIX -DURTBLDENV_FRIENDLY=Debug -D_DBG -D_DEBUG -D_FILE_OFFSET_BITS=64 -DSTATIC_ICU -DSTATIC_SHIM_COMPILE) +add_definitions(-D_GNU_SOURCE -g -fPIC -DHOST_64BIT -DHOST_AMD64 -DHOST_UNIX -DPALEXPORT=EXTERN_C -DTARGET_64BIT -DTARGET_AMD64 -DTARGET_LINUX -DTARGET_UNIX -D_FILE_OFFSET_BITS=64 -DSTATIC_ICU -DSTATIC_SHIM_COMPILE) target_compile_options(System.Globalization.Native-Static PUBLIC -std=gnu99 -Wno-declaration-after-statement -D_GNU_SOURCE -g -fPIC -O0 -g -Wall -fno-omit-frame-pointer -fms-extensions -fwrapv -fstack-protector-strong) -target_include_directories (System.Globalization.Native-Static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../Common ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../../ ${CMAKE_CURRENT_SOURCE_DIR}/build) +target_include_directories (System.Globalization.Native-Static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../ ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/Common ${CMAKE_CURRENT_BINARY_DIR}) +else() + message( FATAL_ERROR "Static builds are supported only on Linux" ) endif() diff --git a/src/native/libs/System.Globalization.Native/static-build/build-nativeaot-shim-standalone.sh b/src/native/libs/System.Globalization.Native/static-build/build-nativeaot-shim-standalone.sh new file mode 100755 index 0000000000000..271621beaa8c5 --- /dev/null +++ b/src/native/libs/System.Globalization.Native/static-build/build-nativeaot-shim-standalone.sh @@ -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/source_code +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 "build-standalone.sh::ERROR: Cannot use local build directory"; exit 1; fi + cmake -S "$SHIM_SOURCE_DIR/libs/System.Globalization.Native/" "$SHIM_SOURCE_DIR/libs/System.Globalization.Native/static-build" + if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: cmake failed"; exit 1; fi + make VERBOSE=1 -j + if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Build failed"; exit 1; fi +fi + +exit 0 From 2f440a049dd0ed60eb5bd9748b8cc8c910f80509 Mon Sep 17 00:00:00 2001 From: smhmhmd Date: Tue, 16 Aug 2022 17:41:54 +0000 Subject: [PATCH 07/17] Fix DirectPInvoke for library built by user --- .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets | 5 +++-- .../System.Globalization.Native/static-build/CMakeLists.txt | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index ed6e891ed4333..4eaa6b68fe896 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -52,7 +52,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + @@ -64,7 +64,8 @@ The .NET Foundation licenses this file to you under the MIT license. $(IlcFrameworkNativePath)lib%(Identity).a - + + diff --git a/src/native/libs/System.Globalization.Native/static-build/CMakeLists.txt b/src/native/libs/System.Globalization.Native/static-build/CMakeLists.txt index 4206d7367d04d..71b96a7a65501 100644 --- a/src/native/libs/System.Globalization.Native/static-build/CMakeLists.txt +++ b/src/native/libs/System.Globalization.Native/static-build/CMakeLists.txt @@ -19,7 +19,7 @@ set(NATIVEGLOBALIZATION_SOURCES ../pal_timeZoneInfo.c ) -add_library(System.Globalization.Native-Static +add_library(System.Globalization.Native STATIC ${NATIVEGLOBALIZATION_SOURCES} ) @@ -38,9 +38,9 @@ add_compile_options(-Wno-unknown-warning-option) add_definitions(-D_GNU_SOURCE -g -fPIC -DHOST_64BIT -DHOST_AMD64 -DHOST_UNIX -DPALEXPORT=EXTERN_C -DTARGET_64BIT -DTARGET_AMD64 -DTARGET_LINUX -DTARGET_UNIX -D_FILE_OFFSET_BITS=64 -DSTATIC_ICU -DSTATIC_SHIM_COMPILE) -target_compile_options(System.Globalization.Native-Static PUBLIC -std=gnu99 -Wno-declaration-after-statement -D_GNU_SOURCE -g -fPIC -O0 -g -Wall -fno-omit-frame-pointer -fms-extensions -fwrapv -fstack-protector-strong) +target_compile_options(System.Globalization.Native PUBLIC -std=gnu99 -Wno-declaration-after-statement -D_GNU_SOURCE -g -fPIC -O0 -g -Wall -fno-omit-frame-pointer -fms-extensions -fwrapv -fstack-protector-strong) -target_include_directories (System.Globalization.Native-Static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../ ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/Common ${CMAKE_CURRENT_BINARY_DIR}) +target_include_directories (System.Globalization.Native PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../ ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/Common ${CMAKE_CURRENT_BINARY_DIR}) else() message( FATAL_ERROR "Static builds are supported only on Linux" ) From e59cc03d902c1f530d2191770f97c324b9de266d Mon Sep 17 00:00:00 2001 From: smhmhmd Date: Wed, 31 Aug 2022 22:01:38 +0000 Subject: [PATCH 08/17] Feedback on 08/25: rename static-build, "source_code" and cleanup compile defs * Remove IlcHostPackagePath check * StaticICULinking property is true/false * Remove -g and -fPIC from definitions * Use minimal warning level * Remove -DHOST_AMD64 * Remove -O0 * Remove -fms-extensions -fwrapv * Standardize on "local build" * Rename build-nativeaot-shim-standalone.sh to build.sh * Script name in the error message should match the actual script name * Rename source_code to native/src Test code: $ cat Program.cs using System.Globalization; namespace CurrentCulture { class Program { static void Main(string[] args) { double val = 1235.56; Console.WriteLine($"Current culture: {CultureInfo.CurrentCulture.Name}"); Console.WriteLine(val); CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); Console.WriteLine($"Current culture: {CultureInfo.CurrentCulture.Name}"); Console.WriteLine(val); } } } $ cat hello-4.csproj Exe net7.0 hello_4 enable enable $ cat nuget.config Test code build: rm ./bin/Debug/net7.0/linux-arm64/native/hello-4 ~/dotnet-sdk/dotnet clean ~/dotnet-sdk/dotnet publish /p:PublishAot=true /p:StaticICULinking=true -bl -r linux-arm64 --self-contained -v d 2>&1 > log ./bin/Debug/net7.0/linux-arm64/native/hello-4 Tested on x86-64 and arm64 --- .../Microsoft.NETCore.Native.Unix.targets | 12 ++--- .../Microsoft.DotNet.ILCompiler.pkgproj | 8 ++-- .../local-build/CMakeLists.txt | 35 ++++++++++++++ .../build.sh} | 10 ++-- .../static-build/CMakeLists.txt | 47 ------------------- 5 files changed, 50 insertions(+), 62 deletions(-) create mode 100644 src/native/libs/System.Globalization.Native/local-build/CMakeLists.txt rename src/native/libs/System.Globalization.Native/{static-build/build-nativeaot-shim-standalone.sh => local-build/build.sh} (64%) delete mode 100644 src/native/libs/System.Globalization.Native/static-build/CMakeLists.txt diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 4eaa6b68fe896..f171ba45d4d51 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -52,7 +52,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + @@ -64,10 +64,10 @@ The .NET Foundation licenses this file to you under the MIT license. $(IlcFrameworkNativePath)lib%(Identity).a - - + + - + @@ -77,7 +77,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + @@ -96,7 +96,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + diff --git a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj index 14c453e6ac363..4131cbb5fc47b 100644 --- a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj +++ b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj @@ -21,10 +21,10 @@ - - - - + + + + diff --git a/src/native/libs/System.Globalization.Native/local-build/CMakeLists.txt b/src/native/libs/System.Globalization.Native/local-build/CMakeLists.txt new file mode 100644 index 0000000000000..0e30837bdae60 --- /dev/null +++ b/src/native/libs/System.Globalization.Native/local-build/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.6) + +project(System.Globalization.Native.Local.Build C) + +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") # Only Linux for now + +configure_file(../config.h.in config.h) + +set(NATIVEGLOBALIZATION_SOURCES + ../pal_calendarData.c + ../pal_casing.c + ../pal_collation.c + ../pal_idna.c + ../pal_locale.c + ../pal_localeNumberData.c + ../pal_localeStringData.c + ../pal_normalization.c + ../pal_icushim_static.c + ../pal_timeZoneInfo.c +) + +add_library(System.Globalization.Native + STATIC + ${NATIVEGLOBALIZATION_SOURCES} +) + +add_definitions(-DPALEXPORT=EXTERN_C -DTARGET_UNIX -DSTATIC_ICU -DSTATIC_SHIM_COMPILE) + +target_compile_options(System.Globalization.Native PUBLIC -std=gnu99 -fPIC -fno-omit-frame-pointer -fstack-protector-strong) + +target_include_directories (System.Globalization.Native PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../ ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/Common ${CMAKE_CURRENT_BINARY_DIR}) + +else() + message( FATAL_ERROR "Static builds are supported only on Linux" ) +endif() diff --git a/src/native/libs/System.Globalization.Native/static-build/build-nativeaot-shim-standalone.sh b/src/native/libs/System.Globalization.Native/local-build/build.sh similarity index 64% rename from src/native/libs/System.Globalization.Native/static-build/build-nativeaot-shim-standalone.sh rename to src/native/libs/System.Globalization.Native/local-build/build.sh index 271621beaa8c5..2e025553182ff 100755 --- a/src/native/libs/System.Globalization.Native/static-build/build-nativeaot-shim-standalone.sh +++ b/src/native/libs/System.Globalization.Native/local-build/build.sh @@ -10,17 +10,17 @@ # Currently, only Linux is supported -SHIM_SOURCE_DIR=$1/source_code +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 "build-standalone.sh::ERROR: Cannot use local build directory"; exit 1; fi - cmake -S "$SHIM_SOURCE_DIR/libs/System.Globalization.Native/" "$SHIM_SOURCE_DIR/libs/System.Globalization.Native/static-build" - if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: cmake failed"; exit 1; fi + if [ $? -ne 0 ]; then echo "build.sh::ERROR: Cannot use local build directory"; exit 1; fi + cmake -S "$SHIM_SOURCE_DIR/libs/System.Globalization.Native/" "$SHIM_SOURCE_DIR/libs/System.Globalization.Native/local-build" + if [ $? -ne 0 ]; then echo "build.sh::ERROR: cmake failed"; exit 1; fi make VERBOSE=1 -j - if [ $? -ne 0 ]; then echo "build-standalone.sh::ERROR: Build failed"; exit 1; fi + if [ $? -ne 0 ]; then echo "build.sh::ERROR: Build failed"; exit 1; fi fi exit 0 diff --git a/src/native/libs/System.Globalization.Native/static-build/CMakeLists.txt b/src/native/libs/System.Globalization.Native/static-build/CMakeLists.txt deleted file mode 100644 index 71b96a7a65501..0000000000000 --- a/src/native/libs/System.Globalization.Native/static-build/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -cmake_minimum_required(VERSION 3.6) - -project(System.Globalization.Native.User.Machine.Build C) - -if(CMAKE_SYSTEM_NAME STREQUAL "Linux") # Only Linux for now - -configure_file(../config.h.in config.h) - -set(NATIVEGLOBALIZATION_SOURCES - ../pal_calendarData.c - ../pal_casing.c - ../pal_collation.c - ../pal_idna.c - ../pal_locale.c - ../pal_localeNumberData.c - ../pal_localeStringData.c - ../pal_normalization.c - ../pal_icushim_static.c - ../pal_timeZoneInfo.c -) - -add_library(System.Globalization.Native - STATIC - ${NATIVEGLOBALIZATION_SOURCES} -) - -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) - -# Workaround for https://unicode-org.atlassian.net/browse/ICU-20601 -add_compile_options(-Wno-extra-semi-stmt) -add_compile_options(-Wno-unknown-warning-option) - -add_definitions(-D_GNU_SOURCE -g -fPIC -DHOST_64BIT -DHOST_AMD64 -DHOST_UNIX -DPALEXPORT=EXTERN_C -DTARGET_64BIT -DTARGET_AMD64 -DTARGET_LINUX -DTARGET_UNIX -D_FILE_OFFSET_BITS=64 -DSTATIC_ICU -DSTATIC_SHIM_COMPILE) - -target_compile_options(System.Globalization.Native PUBLIC -std=gnu99 -Wno-declaration-after-statement -D_GNU_SOURCE -g -fPIC -O0 -g -Wall -fno-omit-frame-pointer -fms-extensions -fwrapv -fstack-protector-strong) - -target_include_directories (System.Globalization.Native PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../ ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/Common ${CMAKE_CURRENT_BINARY_DIR}) - -else() - message( FATAL_ERROR "Static builds are supported only on Linux" ) -endif() From 4a67db088bf1d6dec6cc5a722453d78040ca2e5b Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sat, 3 Sep 2022 03:32:24 +0000 Subject: [PATCH 09/17] Feedback on 09/02 * Incorporated change to use only src/native/libs/System.Globalization.Native/CMakeLists.txt * Conditionalized CMakeLists.txt for local build * Moved the build.sh into parent as local_build.sh and removed local-build directory. * Rename STATIC_SHIM_COMPILE to LOCAL_BUILD --- .../Microsoft.NETCore.Native.Unix.targets | 11 +++--- .../Microsoft.DotNet.ILCompiler.pkgproj | 1 - .../CMakeLists.txt | 14 +++++++- .../local-build/CMakeLists.txt | 35 ------------------- .../{local-build/build.sh => local_build.sh} | 10 +++--- .../pal_icushim_internal.h | 2 +- .../pal_icushim_static.c | 2 +- 7 files changed, 27 insertions(+), 48 deletions(-) delete mode 100644 src/native/libs/System.Globalization.Native/local-build/CMakeLists.txt rename src/native/libs/System.Globalization.Native/{local-build/build.sh => local_build.sh} (67%) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index f171ba45d4d51..3b509a7668c48 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -64,10 +64,13 @@ The .NET Foundation licenses this file to you under the MIT license. $(IlcFrameworkNativePath)lib%(Identity).a - - - + + + + + + @@ -77,7 +80,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + diff --git a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj index 4131cbb5fc47b..f1e28e9f57f15 100644 --- a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj +++ b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj @@ -22,7 +22,6 @@ - diff --git a/src/native/libs/System.Globalization.Native/CMakeLists.txt b/src/native/libs/System.Globalization.Native/CMakeLists.txt index a41e66cacd310..9a2919713782f 100644 --- a/src/native/libs/System.Globalization.Native/CMakeLists.txt +++ b/src/native/libs/System.Globalization.Native/CMakeLists.txt @@ -57,9 +57,21 @@ set(NATIVEGLOBALIZATION_SOURCES pal_localeNumberData.c pal_localeStringData.c pal_normalization.c - pal_icushim.c ) +if (DEFINED 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() diff --git a/src/native/libs/System.Globalization.Native/local-build/CMakeLists.txt b/src/native/libs/System.Globalization.Native/local-build/CMakeLists.txt deleted file mode 100644 index 0e30837bdae60..0000000000000 --- a/src/native/libs/System.Globalization.Native/local-build/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -cmake_minimum_required(VERSION 3.6) - -project(System.Globalization.Native.Local.Build C) - -if(CMAKE_SYSTEM_NAME STREQUAL "Linux") # Only Linux for now - -configure_file(../config.h.in config.h) - -set(NATIVEGLOBALIZATION_SOURCES - ../pal_calendarData.c - ../pal_casing.c - ../pal_collation.c - ../pal_idna.c - ../pal_locale.c - ../pal_localeNumberData.c - ../pal_localeStringData.c - ../pal_normalization.c - ../pal_icushim_static.c - ../pal_timeZoneInfo.c -) - -add_library(System.Globalization.Native - STATIC - ${NATIVEGLOBALIZATION_SOURCES} -) - -add_definitions(-DPALEXPORT=EXTERN_C -DTARGET_UNIX -DSTATIC_ICU -DSTATIC_SHIM_COMPILE) - -target_compile_options(System.Globalization.Native PUBLIC -std=gnu99 -fPIC -fno-omit-frame-pointer -fstack-protector-strong) - -target_include_directories (System.Globalization.Native PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../ ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/Common ${CMAKE_CURRENT_BINARY_DIR}) - -else() - message( FATAL_ERROR "Static builds are supported only on Linux" ) -endif() diff --git a/src/native/libs/System.Globalization.Native/local-build/build.sh b/src/native/libs/System.Globalization.Native/local_build.sh similarity index 67% rename from src/native/libs/System.Globalization.Native/local-build/build.sh rename to src/native/libs/System.Globalization.Native/local_build.sh index 2e025553182ff..0ace96373a36e 100755 --- a/src/native/libs/System.Globalization.Native/local-build/build.sh +++ b/src/native/libs/System.Globalization.Native/local_build.sh @@ -16,11 +16,11 @@ 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 "build.sh::ERROR: Cannot use local build directory"; exit 1; fi - cmake -S "$SHIM_SOURCE_DIR/libs/System.Globalization.Native/" "$SHIM_SOURCE_DIR/libs/System.Globalization.Native/local-build" - if [ $? -ne 0 ]; then echo "build.sh::ERROR: cmake failed"; exit 1; fi - make VERBOSE=1 -j - if [ $? -ne 0 ]; then echo "build.sh::ERROR: Build failed"; exit 1; fi + 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 diff --git a/src/native/libs/System.Globalization.Native/pal_icushim_internal.h b/src/native/libs/System.Globalization.Native/pal_icushim_internal.h index 4545af0ef96c0..e349b47f28802 100644 --- a/src/native/libs/System.Globalization.Native/pal_icushim_internal.h +++ b/src/native/libs/System.Globalization.Native/pal_icushim_internal.h @@ -15,7 +15,7 @@ #include "pal_icushim_internal_android.h" #else -#if !defined(STATIC_SHIM_COMPILE) +#if !defined(LOCAL_BUILD) #define U_DISABLE_RENAMING 1 #endif diff --git a/src/native/libs/System.Globalization.Native/pal_icushim_static.c b/src/native/libs/System.Globalization.Native/pal_icushim_static.c index 288355b585691..cd57172b52329 100644 --- a/src/native/libs/System.Globalization.Native/pal_icushim_static.c +++ b/src/native/libs/System.Globalization.Native/pal_icushim_static.c @@ -217,7 +217,7 @@ const char* GlobalizationNative_GetICUDTName(const char* culture) int32_t GlobalizationNative_LoadICU(void) { -#if !defined(STATIC_SHIM_COMPILE) +#if !defined(LOCAL_BUILD) // Static NativeAOT compilation does not have // GlobalizationNative_LoadICUData() as entrypoint if (!isDataSet) From ff907cf46a4793cd9785d2e325027a2faa8fb4b2 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 4 Sep 2022 18:00:24 +0000 Subject: [PATCH 10/17] Move file includes to previous itemgroup Move the includes in Microsoft.DotNet.ILCompiler.pkgproj to --- .../Microsoft.DotNet.ILCompiler.pkgproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj index f1e28e9f57f15..9868380edd2f1 100644 --- a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj +++ b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj @@ -15,15 +15,15 @@ + + + - - - From 0a11c50740e7577b3303330f767c9d7c8885cd15 Mon Sep 17 00:00:00 2001 From: Samiullah Mohammed Date: Sun, 4 Sep 2022 18:00:24 +0000 Subject: [PATCH 11/17] Move file includes to previous itemgroup Move the includes in Microsoft.DotNet.ILCompiler.pkgproj to --- .../Microsoft.DotNet.ILCompiler.pkgproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj index f1e28e9f57f15..9868380edd2f1 100644 --- a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj +++ b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj @@ -15,15 +15,15 @@ + + + - - - From e5c2c51f35b9755881f8fca32f3e3dfc2e27b359 Mon Sep 17 00:00:00 2001 From: Samiullah Mohammed Date: Sun, 4 Sep 2022 16:54:50 -0700 Subject: [PATCH 12/17] Update section in compiling.md * Add "Using statically linked ICU" to compiling.md * Remove define check for LOCAL_BUILD in CMakeLists.txt --- src/coreclr/nativeaot/docs/compiling.md | 19 +++++++++++++++++++ .../CMakeLists.txt | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/docs/compiling.md b/src/coreclr/nativeaot/docs/compiling.md index f142fa3afecb1..89ff93b4d16c6 100644 --- a/src/coreclr/nativeaot/docs/compiling.md +++ b/src/coreclr/nativeaot/docs/compiling.md @@ -68,3 +68,22 @@ 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 + + true + +``` + +### Prerequisites + +Ubuntu (20.04+) +``` +sudo apt-get install libicu-dev cmake +``` diff --git a/src/native/libs/System.Globalization.Native/CMakeLists.txt b/src/native/libs/System.Globalization.Native/CMakeLists.txt index 9a2919713782f..5e2fb2948cc43 100644 --- a/src/native/libs/System.Globalization.Native/CMakeLists.txt +++ b/src/native/libs/System.Globalization.Native/CMakeLists.txt @@ -59,7 +59,7 @@ set(NATIVEGLOBALIZATION_SOURCES pal_normalization.c ) -if (DEFINED LOCAL_BUILD) +if (LOCAL_BUILD) set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim_static.c) add_definitions(-DLOCAL_BUILD) add_definitions(-DSTATIC_ICU) From 40bf9be0c8820cd33ac1ab8e2aacbb1588665dfa Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sun, 4 Sep 2022 17:02:34 -0700 Subject: [PATCH 13/17] Update src/coreclr/nativeaot/docs/compiling.md --- src/coreclr/nativeaot/docs/compiling.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/docs/compiling.md b/src/coreclr/nativeaot/docs/compiling.md index 89ff93b4d16c6..a72c86cb9b9cc 100644 --- a/src/coreclr/nativeaot/docs/compiling.md +++ b/src/coreclr/nativeaot/docs/compiling.md @@ -70,7 +70,7 @@ 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.
+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: From 5f9e7a703c44cda3c0e26a39fec97120e21ae4a3 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sun, 4 Sep 2022 17:03:52 -0700 Subject: [PATCH 14/17] Update src/coreclr/nativeaot/docs/compiling.md --- src/coreclr/nativeaot/docs/compiling.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/nativeaot/docs/compiling.md b/src/coreclr/nativeaot/docs/compiling.md index a72c86cb9b9cc..f59984ae55e03 100644 --- a/src/coreclr/nativeaot/docs/compiling.md +++ b/src/coreclr/nativeaot/docs/compiling.md @@ -79,7 +79,6 @@ You can use this feature by adding the `StaticICULinking` property to your proje true -``` ### Prerequisites From e4fdcfa7afd11a3355831dc1063f12a45227d723 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sun, 4 Sep 2022 17:07:37 -0700 Subject: [PATCH 15/17] Update src/coreclr/nativeaot/docs/compiling.md --- src/coreclr/nativeaot/docs/compiling.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/coreclr/nativeaot/docs/compiling.md b/src/coreclr/nativeaot/docs/compiling.md index f59984ae55e03..ed7e135565f55 100644 --- a/src/coreclr/nativeaot/docs/compiling.md +++ b/src/coreclr/nativeaot/docs/compiling.md @@ -79,6 +79,9 @@ You can use this feature by adding the `StaticICULinking` property to your proje true +``` + +This feature is only supported on Linux. ### Prerequisites From 7a96d14e9245c660b8a325b4fdc85e6510e9d6eb Mon Sep 17 00:00:00 2001 From: Samiullah Mohammed Date: Sun, 4 Sep 2022 20:49:11 -0700 Subject: [PATCH 16/17] Update src/coreclr/nativeaot/docs/compiling.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michal Strehovský --- src/coreclr/nativeaot/docs/compiling.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/docs/compiling.md b/src/coreclr/nativeaot/docs/compiling.md index ed7e135565f55..c84d11825aea2 100644 --- a/src/coreclr/nativeaot/docs/compiling.md +++ b/src/coreclr/nativeaot/docs/compiling.md @@ -81,7 +81,7 @@ You can use this feature by adding the `StaticICULinking` property to your proje ``` -This feature is only supported on Linux. +This feature is only supported on Linux. This feature is not supported when crosscompiling. ### Prerequisites From 8323197b884da86270eb19c85facd2c4be7225d0 Mon Sep 17 00:00:00 2001 From: Samiullah Mohammed Date: Sun, 4 Sep 2022 21:14:19 -0700 Subject: [PATCH 17/17] Update src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michal Strehovský --- .../Microsoft.DotNet.ILCompiler.pkgproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj index 9868380edd2f1..6624b2f5c275f 100644 --- a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj +++ b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj @@ -15,6 +15,8 @@ + +