Parcourir la source

Allow ChakraFull to build with Windows Kit ICU

Jack Horton il y a 8 ans
Parent
commit
b30c7a53ce

+ 16 - 7
Build/Chakra.Build.props

@@ -25,9 +25,14 @@
     <!-- ARM does not support ICU until we figure out how to link icudtXXl.dat without genccode.exe -->
     <ChakraICU Condition="'$(Platform)'=='ARM'">false</ChakraICU>
 
+    <WindowsICU Condition="'$(WindowsICU)'==''">false</WindowsICU>
+
     <UseICU Condition="'$(UseICU)'==''">false</UseICU>
     <UseICU Condition="'$(BuildLite)'=='true'">false</UseICU>
-    <UseICU Condition="'$(ChakraICU)'!='false'">true</UseICU>
+    <UseICU Condition="'$(ChakraICU)'!='false' OR '$(WindowsICU)'=='true'">true</UseICU>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(WindowsICU)'=='true'">
+    <IcuLibraryDependencies>icuuc.lib;icuin.lib</IcuLibraryDependencies>
   </PropertyGroup>
   <Import Condition="'$(ChakraICU)'!='false' AND exists('$(ChakraCoreRootDirectory)deps\Chakra.ICU\Chakra.ICU.props')" Project="$(ChakraCoreRootDirectory)deps\Chakra.ICU\Chakra.ICU.props" />
   <ItemDefinitionGroup>
@@ -53,7 +58,8 @@
       </PreprocessorDefinitions>
       <PreprocessorDefinitions Condition="'$(UseICU)'=='true'">
         %(PreprocessorDefinitions);
-        HAS_ICU
+        HAS_ICU;
+        U_DISABLE_RENAMING=1; <!-- Disable renaming to maintain compatibility with Windows Kit ICU's icuuc/icuin.lib -->
       </PreprocessorDefinitions>
       <PreprocessorDefinitions Condition="'$(EnableIntl)'=='true' AND '$(UseICU)'=='true'">
         %(PreprocessorDefinitions);
@@ -63,10 +69,13 @@
         %(PreprocessorDefinitions);
         U_STATIC_IMPLEMENTATION=1
       </PreprocessorDefinitions>
-      <PreprocessorDefinitions Condition="'$(UseICU)'=='true'">
-        U_DISABLE_RENAMING=1; <!-- Disable renaming to maintain compatibility with Windows Kit ICU's icuuc/icuin.lib -->
-        ICU_VERSION=$(IcuVersionMajor);
-        %(PreprocessorDefinitions)
+      <PreprocessorDefinitions Condition="'$(WindowsICU)'=='true'">
+        %(PreprocessorDefinitions);
+        WINDOWS10_ICU
+      </PreprocessorDefinitions>
+      <PreprocessorDefinitions Condition="'$(WindowsICU)'=='false'">
+        %(PreprocessorDefinitions);
+        ICU_VERSION=$(IcuVersionMajor)
       </PreprocessorDefinitions>
       <PreprocessorDefinitions Condition="'$(ForceSWB)'=='true'">
         %(PreprocessorDefinitions);
@@ -78,7 +87,7 @@
         %(DisableSpecificWarnings);
         4458;     <!-- declaration of '' hides class member -->
         4312;     <!-- 'type cast': conversion from '' to '' of greater size -->
-        4800;     <!-- type' : forcing value to bool 'true' or 'false' (performance warning) [always off in 2017 by default, but warns in 2015 -->
+        4800;     <!-- 'type' : forcing value to bool 'true' or 'false' (performance warning) [always off in 2017 by default, but warns in 2015] -->
       </DisableSpecificWarnings>
       <!-- Use the debug CRT in debug build -->
       <RuntimeLibrary Condition="'$(Configuration)'=='Debug' AND '$(RuntimeLib)'!='static_library'">MultiThreadedDebugDLL</RuntimeLibrary>

+ 1 - 1
bin/ChakraCore/ChakraCore.vcxproj

@@ -53,7 +53,7 @@
         $(ChakraCommonLinkDependencies)
       </AdditionalDependencies>
       <AdditionalDependencies Condition="'$(UseICU)'=='true' AND '$(ChakraICU)'=='false'">
-        $(IcuLibraryDependencies)
+        $(IcuLibraryDependencies);
         %(AdditionalDependencies)
       </AdditionalDependencies>
       <DelayLoadDLLs>%(DelayLoadDLLs);oleaut32.dll</DelayLoadDLLs>

+ 3 - 0
bin/ch/CMakeLists.txt

@@ -91,6 +91,9 @@ else() # // shared library below
     PRIVATE Chakra.Common.Codex.Singular
     PRIVATE Chakra.Runtime.PlatformAgnostic.Singular
     )
+
+  # Link explicitly to ICU to support u_getVersion
+  set(lib_target ${lib_target} ${ICU_LIBRARIES})
 endif()
 
 if(CC_TARGET_OS_ANDROID OR CC_TARGET_OS_LINUX)

+ 6 - 1
bin/ch/WScriptJsrt.cpp

@@ -909,6 +909,11 @@ bool WScriptJsrt::Initialize()
 #else
     const char* LINK_TYPE = "shared";
 #endif
+#ifdef HAS_ICU
+    int icuVersion = PlatformAgnostic::ICUHelpers::GetICUMajorVersion();
+#else
+    int icuVersion = -1;
+#endif
 
     JsValueRef wscript;
     IfJsrtErrorFail(ChakraRTInterface::JsCreateObject(&wscript), false);
@@ -1005,7 +1010,7 @@ bool WScriptJsrt::Initialize()
     JsPropertyIdRef icuVersionProp;
     IfJsrtErrorFail(CreatePropertyIdFromString("ICU_VERSION", &icuVersionProp), false);
     JsValueRef icuVersionNum;
-    IfJsrtErrorFail(ChakraRTInterface::JsIntToNumber(ICU_VERSION, &icuVersionNum), false);
+    IfJsrtErrorFail(ChakraRTInterface::JsIntToNumber(icuVersion, &icuVersionNum), false);
     IfJsrtErrorFail(ChakraRTInterface::JsSetProperty(platformObject, icuVersionProp, icuVersionNum, true), false);
 
     IfJsrtErrorFail(ChakraRTInterface::JsSetProperty(wscript, platformProperty,

+ 14 - 1
bin/ch/ch.vcxproj

@@ -27,6 +27,11 @@
         $(IntDir);
         %(AdditionalIncludeDirectories);
       </AdditionalIncludeDirectories>
+      <!-- For ChakraICU.h -->
+      <AdditionalIncludeDirectories Condition="'$(UseICU)'=='true'">
+        $(ChakraCoreRootDirectory)lib\Runtime;
+        %(AdditionalIncludeDirectories)
+      </AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <ModuleDefinitionFile>ch.def</ModuleDefinitionFile>
@@ -39,6 +44,10 @@
         Rpcrt4.lib;
         version.lib;
       </AdditionalDependencies>
+      <AdditionalDependencies Condition="'$(UseICU)'=='true' AND '$(ChakraICU)'=='false'">
+        $(IcuLibraryDependencies);
+        %(AdditionalDependencies)
+      </AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
@@ -88,6 +97,10 @@
     <ProjectReference Include="..\ChakraCore\ChakraCore.vcxproj">
       <Project>{EA882C8D-81FC-42FE-ABD5-2666DB933FDB}</Project>
     </ProjectReference>
+    <!-- for u_getVersion() referenced in PlatformAgnostic::ICUHelpers::GetICUMajorVersion -->
+    <ProjectReference Condition="'$(ChakraICU)'!='false'" Include="..\..\deps\Chakra.ICU\Chakra.ICU.Common.vcxproj">
+      <Project>{EE2A3111-4D85-427C-B0AB-E6B0EA7FFB44}</Project>
+    </ProjectReference>
   </ItemGroup>
   <ItemGroup>
     <None Include="262.js" />
@@ -106,4 +119,4 @@
   </ItemGroup>
   <Import Project="$(BuildConfigPropsPath)Chakra.Build.targets" Condition="exists('$(BuildConfigPropsPath)Chakra.Build.targets')" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-</Project>
+</Project>

+ 3 - 0
bin/ch/stdafx.h

@@ -88,6 +88,9 @@ using utf8::WideStringToNarrowDynamic;
 #include "Helpers.h"
 
 #include "PlatformAgnostic/SystemInfo.h"
+#ifdef HAS_ICU
+#include "PlatformAgnostic/ChakraICU.h"
+#endif
 
 #define IfJsErrorFailLog(expr) \
 do { \

+ 6 - 20
lib/Common/CommonDefines.h

@@ -110,21 +110,14 @@
 #define ENABLE_UNICODE_API 1                        // Enable use of Unicode-related APIs
 #endif
 
-// Normalize ICU_VERSION which is set by the build system on Windows
-// because U_ICU_VERSION_MAJOR_NUM is not available in Windows Kit ICU
-#if defined(HAS_ICU) && !defined(ICU_VERSION)
-#ifndef WINDOWS10_ICU
+// Normalize ICU_VERSION for non-Kit ICU
+#if defined(HAS_ICU) && !defined(ICU_VERSION) && !defined(WINDOWS10_ICU)
 #include "unicode/uvernum.h"
 #define ICU_VERSION U_ICU_VERSION_MAJOR_NUM
-#else
-#error "No ICU version information"
-#endif
-#else
-#define ICU_VERSION -1
 #endif
 
-// ICU Configuration
-#if defined(HAS_ICU) || defined(HAS_REAL_ICU)
+// Make non-Windows Kit ICU look and act like Windows Kit ICU for better compat
+#if defined(HAS_ICU) && !defined(WINDOWS10_ICU)
 #define U_SHOW_CPLUSPLUS_API 0
 // ICU 55 (Ubuntu 16.04 system default) has uloc_toUnicodeLocale* marked as draft, which is required for Intl
 #if ICU_VERSION > 56
@@ -137,19 +130,12 @@
 #endif
 
 // Language features
-
 #if !defined(CHAKRACORE_LITE) && (defined(_WIN32) || defined(INTL_ICU))
 #define ENABLE_INTL_OBJECT                          // Intl support
 #define ENABLE_JS_BUILTINS                          // Built In functions support
 #endif
-//#define INTL_ICU 1                    // NOTE: uncomment this to allow the IDE to see INTL_ICU blocks
-#ifdef INTL_ICU
-#ifdef DBG
-//#define INTL_ICU_DEBUG 1              // NOTE: uncomment this to display INTL_ICU-specific debug output
-#endif
-//#define INTL_ICU_ALLOW_HYBRID 1       // NOTE: uncomment this line to test INTL_ICU SxS with INTL_WINGLOB while INTL_ICU is in-development
-#endif
-#if defined(_WIN32) && (!defined(INTL_ICU) || (defined(INTL_ICU) && defined(INTL_ICU_ALLOW_HYBRID)))
+
+#if defined(_WIN32) && !defined(HAS_ICU)
 #define INTL_WINGLOB 1
 #endif
 

+ 2 - 2
lib/Runtime/Library/IntlEngineInterfaceExtensionObject.cpp

@@ -20,7 +20,7 @@ using namespace Windows::Globalization;
 
 #ifdef INTL_ICU
 #include <CommonPal.h>
-#include "PlatformAgnostic/ICU.h"
+#include "PlatformAgnostic/ChakraICU.h"
 using namespace PlatformAgnostic::ICUHelpers;
 
 template<typename ICUFunc>
@@ -2212,7 +2212,7 @@ namespace Js
 
             // status can be U_UNSUPPORTED_ERROR if the calendar isn't gregorian, which
             // there does not seem to be a way to check for ahead of time in the C API
-            AssertOrFailFastMsg(U_SUCCESS(status) || status == U_UNSUPPORTED_ERROR, u_errorName(status));
+            AssertOrFailFastMsg(U_SUCCESS(status) || status == U_UNSUPPORTED_ERROR, ICU_ERRORMESSAGE(status));
 
             // cache dtf for later use (so that the condition that brought us here returns true for future calls)
             state->SetInternalProperty(

+ 1 - 1
lib/Runtime/PlatformAgnostic/Chakra.Runtime.PlatformAgnostic.vcxproj

@@ -57,7 +57,7 @@
     <ClInclude Include="PerfTrace.h" />
     <ClInclude Include="RuntimePlatformAgnosticPch.h" />
     <ClInclude Include="UnicodeText.h" />
-    <ClInclude Include="ICU.h" Condition="'$(UseICU)'=='true'" />
+    <ClInclude Include="ChakraICU.h" Condition="'$(UseICU)'=='true'" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\..\JITIDL\Chakra.JITIDL.vcxproj">

+ 1 - 4
lib/Runtime/PlatformAgnostic/Chakra.Runtime.PlatformAgnostic.vcxproj.filters

@@ -34,10 +34,7 @@
     <ClInclude Include="IPlatformAgnosticResource.h">
       <Filter>Interfaces</Filter>
     </ClInclude>
-    <ClInclude Include="ICU.h">
-      <Filter>Interfaces</Filter>
-    </ClInclude>
-    <ClInclude Include="Intl.h">
+    <ClInclude Include="ChakraICU.h">
       <Filter>Interfaces</Filter>
     </ClInclude>
   </ItemGroup>

+ 13 - 0
lib/Runtime/PlatformAgnostic/ICU.h → lib/Runtime/PlatformAgnostic/ChakraICU.h

@@ -8,7 +8,13 @@
 
 #ifdef HAS_ICU
 #ifdef WINDOWS10_ICU
+// if WINDOWS10_ICU is defined, pretend like we are building for recent Redstone,
+// even if that isn't necessarily true
+#pragma push_macro("NTDDI_VERSION")
+#undef NTDDI_VERSION
+#define NTDDI_VERSION NTDDI_WIN10_RS3
 #include <icu.h>
+#pragma pop_macro("NTDDI_VERSION")
 #else
 #include "unicode/ucal.h"
 #include "unicode/ucol.h"
@@ -93,6 +99,13 @@ namespace PlatformAgnostic
             }
             return U_SUCCESS(status) && status != U_STRING_NOT_TERMINATED_WARNING && *returnLen > 0;
         }
+
+        inline int GetICUMajorVersion()
+        {
+            UVersionInfo version = { 0 };
+            u_getVersion(version);
+            return version[0];
+        }
     }
 }
 #endif

+ 3 - 3
lib/Runtime/PlatformAgnostic/Platform/Common/UnicodeText.ICU.cpp

@@ -5,7 +5,7 @@
 
 #include "RuntimePlatformAgnosticPch.h"
 #include "UnicodeText.h"
-#include "ICU.h"
+#include "ChakraICU.h"
 
 namespace PlatformAgnostic
 {
@@ -48,7 +48,7 @@ namespace PlatformAgnostic
 
             UErrorCode status = U_ZERO_ERROR;
             const UNormalizer2 *normalizer = unorm2_getInstance(nullptr, name, mode, &status);
-            AssertMsg(U_SUCCESS(status), u_errorName(status));
+            AssertMsg(U_SUCCESS(status), ICU_ERRORMESSAGE(status));
             return normalizer;
         }
 
@@ -214,7 +214,7 @@ namespace PlatformAgnostic
 
             UErrorCode status = U_ZERO_ERROR;
             bool isNormalized = unorm2_isNormalized(normalizer, reinterpret_cast<const UChar *>(testString), testStringLength, &status);
-            AssertMsg(U_SUCCESS(status), u_errorName(status));
+            AssertMsg(U_SUCCESS(status), ICU_ERRORMESSAGE(status));
 
             return isNormalized;
         }

+ 1 - 1
lib/Runtime/PlatformAgnostic/UnicodeText.h

@@ -5,7 +5,7 @@
 #pragma once
 
 #include "Core/CommonTypedefs.h"
-#include "ICU.h"
+#include "ChakraICU.h"
 
 namespace PlatformAgnostic
 {