Skip to content

Commit b942fdb

Browse files
committed
[MERGE #1134] cross-platform: ChakraCore on OSX
Merge pull request #1134 from obastemur:osx_support Disclaimer: Currently, ChakraCore is not officially supported on OSX. This PR targets the individuals interested with experimenting ChakraCore on OSX. After seeing #1131, spent couple of hours to fix the compile, and link time issues on OSX target. Steps to compile : ``` brew install icu4c ./build.sh --debug -j:2 --icu=/usr/local/Cellar/icu4c/54.1/include/ ``` Status: CMAKE has an issue with shared bundles on OSX (a.k.a. so) and currently CH does not play well with dylib.
2 parents c6c8f64 + 807ed43 commit b942fdb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+500
-1028
lines changed

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux)
1919
endif()
2020
set(CLR_CMAKE_PLATFORM_LINUX 1)
2121
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
22-
add_definitions(-DPLATFORM_UNIX)
22+
add_definitions(
23+
-DPLATFORM_UNIX
24+
-DU_DISABLE_RENAMING=1 #in case we link against to an older binary of icu
25+
)
2326

2427
set(CLR_CMAKE_PLATFORM_UNIX 1)
2528
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
@@ -76,6 +79,11 @@ if(CLR_CMAKE_PLATFORM_UNIX)
7679
-Wno-implicit-function-declaration"
7780
)
7881

82+
# todo: fix general visibility of the interface
83+
# do not set to `fvisibility=hidden` as it is going to
84+
# prevent the required interface is being exported
85+
# clang by default sets fvisibility=default
86+
7987
# CXX WARNING FLAGS
8088
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
8189
-Werror\

bin/ChakraCore/CMakeLists.txt

Lines changed: 84 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ add_library (ChakraCore SHARED
33
ConfigParserExternals.cpp
44
TestHooks.cpp
55
)
6-
7-
# By default, don't export any symbols from this library
8-
# We'll manually export the relevant individual functions
9-
set_target_properties(ChakraCore PROPERTIES CXX_VISIBILITY_PRESET hidden)
106

117
target_include_directories (
128
ChakraCore PUBLIC
@@ -32,42 +28,88 @@ target_include_directories (
3228
# dl: For shared library loading related functions
3329
# icuuc: For the ICU (xplat-todo: Make this optional)
3430
#
35-
target_link_libraries(ChakraCore
36-
-Wl,--no-undefined
37-
-Wl,--start-group
38-
-Wl,--whole-archive
39-
Chakra.Jsrt
40-
Chakra.Jsrt.Core
41-
-Wl,--no-whole-archive
42-
Chakra.Runtime.Types
43-
Chakra.Runtime.Math
44-
Chakra.Runtime.Library
45-
Chakra.Runtime.Language
46-
Chakra.Runtime.Debug
47-
Chakra.Runtime.ByteCode
48-
Chakra.Runtime.PlatformAgnostic
49-
Chakra.Runtime.Base
50-
Chakra.Parser
51-
Chakra.Common.Util
52-
Chakra.Common.Memory
53-
Chakra.Common.Common
54-
Chakra.Common.Core
55-
Chakra.Common.DataStructures
56-
Chakra.Common.Exceptions
57-
Chakra.Common.Codex
58-
-Wl,--end-group
59-
Chakra.Pal
60-
pthread
61-
stdc++
62-
dl
63-
icuuc
64-
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libChakraCoreLib.version
65-
)
31+
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
32+
target_link_libraries(ChakraCore
33+
-Wl,--no-undefined
34+
-Wl,--start-group
35+
-Wl,--whole-archive
36+
Chakra.Jsrt
37+
Chakra.Jsrt.Core
38+
-Wl,--no-whole-archive
39+
Chakra.Runtime.Types
40+
Chakra.Runtime.Math
41+
Chakra.Runtime.Library
42+
Chakra.Runtime.Language
43+
Chakra.Runtime.Debug
44+
Chakra.Runtime.ByteCode
45+
Chakra.Runtime.PlatformAgnostic
46+
Chakra.Runtime.Base
47+
Chakra.Parser
48+
Chakra.Common.Util
49+
Chakra.Common.Memory
50+
Chakra.Common.Common
51+
Chakra.Common.Core
52+
Chakra.Common.DataStructures
53+
Chakra.Common.Exceptions
54+
Chakra.Common.Codex
55+
-Wl,--end-group
56+
Chakra.Pal
57+
pthread
58+
stdc++
59+
dl
60+
icuuc
61+
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libChakraCoreLib.version
62+
)
63+
#
64+
# Post build step to copy the built shared library
65+
# to BuildLinux (or whatever the CMakeBuildDir is)
66+
add_custom_command(TARGET ChakraCore POST_BUILD
67+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
68+
"${CHAKRACORE_BINARY_DIR}/bin/ChakraCore/libChakraCore.so"
69+
${CHAKRACORE_BINARY_DIR}/)
70+
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
71+
# todo: combine link libraries into a list
72+
# reminder: order of the link libraries matters
73+
# we miss multiple keywords below
74+
# can we handle the creation of the list
75+
# with a single IF/case per platform?
6676

67-
#
68-
# Post build step to copy the built shared library
69-
# to BuildLinux (or whatever the CMakeBuildDir is)
70-
add_custom_command(TARGET ChakraCore POST_BUILD
71-
COMMAND ${CMAKE_COMMAND} -E copy_if_different
72-
"${CHAKRACORE_BINARY_DIR}/bin/ChakraCore/libChakraCore.so"
73-
${CHAKRACORE_BINARY_DIR}/)
77+
target_link_libraries(ChakraCore
78+
-Wl,-undefined,error
79+
# -Wl,--start-group
80+
# -Wl,--whole-archive
81+
Chakra.Jsrt
82+
Chakra.Jsrt.Core
83+
# -Wl,--no-whole-archive
84+
Chakra.Runtime.Types
85+
Chakra.Runtime.Math
86+
Chakra.Runtime.Library
87+
Chakra.Runtime.Language
88+
Chakra.Runtime.Debug
89+
Chakra.Runtime.ByteCode
90+
Chakra.Runtime.PlatformAgnostic
91+
Chakra.Runtime.Base
92+
Chakra.Parser
93+
Chakra.Common.Util
94+
Chakra.Common.Memory
95+
Chakra.Common.Common
96+
Chakra.Common.Core
97+
Chakra.Common.DataStructures
98+
Chakra.Common.Exceptions
99+
Chakra.Common.Codex
100+
# -Wl,--end-group
101+
Chakra.Pal
102+
pthread
103+
stdc++
104+
dl
105+
icucore
106+
# -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libChakraCoreLib.version
107+
)
108+
#
109+
# Post build step to copy the built shared library
110+
# to BuildLinux (or whatever the CMakeBuildDir is)
111+
add_custom_command(TARGET ChakraCore POST_BUILD
112+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
113+
"${CHAKRACORE_BINARY_DIR}/bin/ChakraCore/libChakraCore.dylib"
114+
${CHAKRACORE_BINARY_DIR}/)
115+
endif()

bin/ch/CMakeLists.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,23 @@ target_include_directories (ch
2222
../../lib/Jsrt
2323
)
2424

25-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie")
26-
27-
target_link_libraries (ch
28-
PRIVATE Chakra.Pal
29-
PRIVATE Chakra.Common.Codex
30-
PRIVATE Chakra.Runtime.PlatformAgnostic
31-
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/ch.version
32-
)
25+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE")
3326

27+
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
28+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") # osx clang adds this by default
29+
target_link_libraries (ch
30+
PRIVATE Chakra.Pal
31+
PRIVATE Chakra.Common.Codex
32+
PRIVATE Chakra.Runtime.PlatformAgnostic
33+
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/ch.version
34+
)
35+
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
36+
target_link_libraries (ch
37+
PRIVATE Chakra.Pal
38+
PRIVATE Chakra.Common.Codex
39+
PRIVATE Chakra.Runtime.PlatformAgnostic
40+
)
41+
endif()
3442
# Add a post build event to the ch target
3543
# which executes a command to copy ch to
3644
# BuildLinux for convenience

bin/ch/ChakraRtInterface.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
LPCSTR chakraDllName = "chakracore.dll";
99
#else
1010
#include <dlfcn.h>
11+
#ifdef __APPLE__
12+
LPCSTR chakraDllName = "libChakraCore.dylib";
13+
#else
1114
LPCSTR chakraDllName = "libChakraCore.so";
1215
#endif
16+
#endif
1317

1418
bool ChakraRTInterface::m_testHooksSetup = false;
1519
bool ChakraRTInterface::m_testHooksInitialized = false;

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ if [[ ${#_CXX} > 0 ]]; then
176176
CC_PREFIX="-DCMAKE_CXX_COMPILER=$_CXX -DCMAKE_C_COMPILER=$_CC"
177177
fi
178178

179-
build_directory="$CHAKRACORE_DIR/BuildLinux/${BUILD_TYPE,,}"
179+
build_directory="$CHAKRACORE_DIR/BuildLinux/${BUILD_TYPE:0}"
180180
if [ ! -d "$build_directory" ]; then
181181
SAFE_RUN `mkdir -p $build_directory`
182182
fi

lib/Runtime/Language/amd64/JavascriptOperatorsA.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
.intel_syntax noprefix
66
#include "unixasmmacros.inc"
77

8+
// expected fvisibility=default
89
.global C_FUNC(amd64_CallWithFakeFrame)
910
.global C_FUNC(amd64_ReturnFromCallWithFakeFrame)
10-
1111
// r8 = arg0.
1212
// rcx = args size.
1313
// rdx = spill size.
@@ -22,7 +22,7 @@ C_FUNC(amd64_CallWithFakeFrame):
2222
// The stack walker uses this marker to skip this frame.
2323
// Note that we use rip-relative addressing here since this
2424
// library is shared and therefore the code has to be position independent
25-
lea rax, [rip+C_FUNC(amd64_ReturnFromCallWithFakeFrame)]
25+
lea rax, [rip + C_FUNC(amd64_ReturnFromCallWithFakeFrame)]
2626
mov [rsp+8h], rax
2727

2828
mov rax, [rsp + 28h]
@@ -57,9 +57,9 @@ C_FUNC(amd64_CallWithFakeFrame):
5757

5858
jmp rdi
5959

60-
6160
// rcx = args size.
6261
// rdx = spill size.
62+
6363
.balign 16
6464
C_FUNC(amd64_ReturnFromCallWithFakeFrame):
6565
add rsp, rcx

lib/Runtime/Library/amd64/JavascriptFunctionA.S

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
.intel_syntax noprefix
77
#include "unixasmmacros.inc"
88

9-
.extern C_FUNC(_ZN2Js18JavascriptFunction13DeferredParseEPPNS_14ScriptFunctionE)
10-
.extern C_FUNC(_ZN2Js18JavascriptFunction19DeferredDeserializeEPNS_14ScriptFunctionE)
11-
129
.global C_FUNC(_ZN2Js18JavascriptFunction20DeferredParsingThunkEPNS_16RecyclableObjectENS_8CallInfoEz)
1310
.global C_FUNC(_ZN2Js18JavascriptFunction24DeferredDeserializeThunkEPNS_16RecyclableObjectENS_8CallInfoEz)
1411

1512
#ifndef __APPLE__
13+
.extern _ZN2Js18JavascriptFunction13DeferredParseEPPNS_14ScriptFunctionE
14+
.extern _ZN2Js18JavascriptFunction19DeferredDeserializeEPNS_14ScriptFunctionE
15+
1616
.type _ZN2Js18JavascriptFunction20DeferredParsingThunkEPNS_16RecyclableObjectENS_8CallInfoEz, @function
1717
.type _ZN2Js18JavascriptFunction24DeferredDeserializeThunkEPNS_16RecyclableObjectENS_8CallInfoEz, @function
1818
#endif
@@ -103,11 +103,12 @@ LOCAL_LABEL(function_done):
103103
lea rsp, [rbp]
104104
pop_nonvol_reg rbp
105105
ret
106+
106107
NESTED_END amd64_CallFunction, _TEXT
107108

108109

109-
// extrn ?DeferredParse@JavascriptFunction@Js@@SAP6APEAXPEAVRecyclableObject@2@UCallInfo@2@ZZPEAPEAVScriptFunction@2@@Z : PROC
110110
.balign 16
111+
.text
111112
C_FUNC(_ZN2Js18JavascriptFunction20DeferredParsingThunkEPNS_16RecyclableObjectENS_8CallInfoEz):
112113
push rbp
113114
lea rbp, [rsp]
@@ -120,14 +121,15 @@ C_FUNC(_ZN2Js18JavascriptFunction20DeferredParsingThunkEPNS_16RecyclableObjectEN
120121
// JavascriptMethod JavascriptFunction::DeferredParse(ScriptFunction**)
121122
//
122123
lea rdi, [rbp + 10h] // &function, setup by custom calling convention
123-
call C_PLTFUNC(_ZN2Js18JavascriptFunction13DeferredParseEPPNS_14ScriptFunctionE)
124+
call C_FUNC(_ZN2Js18JavascriptFunction13DeferredParseEPPNS_14ScriptFunctionE)
124125

125126
pop rsi
126127
pop rdi
127128
pop rbp
128129

129130
jmp rax
130131

132+
131133
// Var JavascriptFunction::DeferredDeserializeThunk(
132134
// RecyclableObject* function, CallInfo callInfo, ...)
133135
.balign 16
@@ -144,7 +146,7 @@ C_FUNC(_ZN2Js18JavascriptFunction24DeferredDeserializeThunkEPNS_16RecyclableObje
144146
// ScriptFunction* function)
145147
//
146148
// RDI == function, setup by custom calling convention
147-
call C_PLTFUNC(_ZN2Js18JavascriptFunction19DeferredDeserializeEPNS_14ScriptFunctionE)
149+
call C_FUNC(_ZN2Js18JavascriptFunction19DeferredDeserializeEPNS_14ScriptFunctionE)
148150

149151
pop rsi
150152
pop rdi
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
project(CHAKRA_PLATFORM_AGNOSTIC)
22

3-
check_function_exists(gmtime_r HAVE_GMTIME_R)
4-
53
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
64
add_library (Chakra.Runtime.PlatformAgnostic
75
Linux/UnicodeText.ICU.cpp
@@ -13,14 +11,15 @@ add_library (Chakra.Runtime.PlatformAgnostic
1311
)
1412
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
1513
add_library (Chakra.Runtime.PlatformAgnostic
16-
#Linux/UnicodeText.ICU.cpp
17-
#Linux/DateTime.cpp
18-
#Linux/HiResTimer.cpp
14+
# xplat-todo: implement them for unix! or carry them into common
15+
Linux/UnicodeText.ICU.cpp
16+
Linux/DateTime.cpp
17+
Linux/HiResTimer.cpp
18+
Linux/NumbersUtility.cpp
1919
Unix/SystemInfo.cpp
2020
Common/UnicodeText.Common.cpp
2121
)
2222
endif()
23-
2423

2524
target_include_directories (
2625
Chakra.Runtime.PlatformAgnostic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

pal/inc/pal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ extern "C" {
6868

6969
#endif
7070

71-
#include <pal_char16.h>
7271
#include <pal_error.h>
7372
#include <pal_mstypes.h>
7473

pal/inc/pal_char16.h

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)