Skip to content

Commit

Permalink
cross-platform: ChakraCore on OSX
Browse files Browse the repository at this point in the history
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 OSX shared bundles and currently CH does not
play well with dylib output.
  • Loading branch information
obastemur committed Jun 18, 2016
1 parent c6c8f64 commit 807ed43
Show file tree
Hide file tree
Showing 48 changed files with 500 additions and 1,028 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux)
endif()
set(CLR_CMAKE_PLATFORM_LINUX 1)
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
add_definitions(-DPLATFORM_UNIX)
add_definitions(
-DPLATFORM_UNIX
-DU_DISABLE_RENAMING=1 #in case we link against to an older binary of icu
)

set(CLR_CMAKE_PLATFORM_UNIX 1)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
Expand Down Expand Up @@ -76,6 +79,11 @@ if(CLR_CMAKE_PLATFORM_UNIX)
-Wno-implicit-function-declaration"
)

# todo: fix general visibility of the interface
# do not set to `fvisibility=hidden` as it is going to
# prevent the required interface is being exported
# clang by default sets fvisibility=default

# CXX WARNING FLAGS
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-Werror\
Expand Down
126 changes: 84 additions & 42 deletions bin/ChakraCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ add_library (ChakraCore SHARED
ConfigParserExternals.cpp
TestHooks.cpp
)

# By default, don't export any symbols from this library
# We'll manually export the relevant individual functions
set_target_properties(ChakraCore PROPERTIES CXX_VISIBILITY_PRESET hidden)

target_include_directories (
ChakraCore PUBLIC
Expand All @@ -32,42 +28,88 @@ target_include_directories (
# dl: For shared library loading related functions
# icuuc: For the ICU (xplat-todo: Make this optional)
#
target_link_libraries(ChakraCore
-Wl,--no-undefined
-Wl,--start-group
-Wl,--whole-archive
Chakra.Jsrt
Chakra.Jsrt.Core
-Wl,--no-whole-archive
Chakra.Runtime.Types
Chakra.Runtime.Math
Chakra.Runtime.Library
Chakra.Runtime.Language
Chakra.Runtime.Debug
Chakra.Runtime.ByteCode
Chakra.Runtime.PlatformAgnostic
Chakra.Runtime.Base
Chakra.Parser
Chakra.Common.Util
Chakra.Common.Memory
Chakra.Common.Common
Chakra.Common.Core
Chakra.Common.DataStructures
Chakra.Common.Exceptions
Chakra.Common.Codex
-Wl,--end-group
Chakra.Pal
pthread
stdc++
dl
icuuc
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libChakraCoreLib.version
)
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
target_link_libraries(ChakraCore
-Wl,--no-undefined
-Wl,--start-group
-Wl,--whole-archive
Chakra.Jsrt
Chakra.Jsrt.Core
-Wl,--no-whole-archive
Chakra.Runtime.Types
Chakra.Runtime.Math
Chakra.Runtime.Library
Chakra.Runtime.Language
Chakra.Runtime.Debug
Chakra.Runtime.ByteCode
Chakra.Runtime.PlatformAgnostic
Chakra.Runtime.Base
Chakra.Parser
Chakra.Common.Util
Chakra.Common.Memory
Chakra.Common.Common
Chakra.Common.Core
Chakra.Common.DataStructures
Chakra.Common.Exceptions
Chakra.Common.Codex
-Wl,--end-group
Chakra.Pal
pthread
stdc++
dl
icuuc
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libChakraCoreLib.version
)
#
# Post build step to copy the built shared library
# to BuildLinux (or whatever the CMakeBuildDir is)
add_custom_command(TARGET ChakraCore POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CHAKRACORE_BINARY_DIR}/bin/ChakraCore/libChakraCore.so"
${CHAKRACORE_BINARY_DIR}/)
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
# todo: combine link libraries into a list
# reminder: order of the link libraries matters
# we miss multiple keywords below
# can we handle the creation of the list
# with a single IF/case per platform?

#
# Post build step to copy the built shared library
# to BuildLinux (or whatever the CMakeBuildDir is)
add_custom_command(TARGET ChakraCore POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CHAKRACORE_BINARY_DIR}/bin/ChakraCore/libChakraCore.so"
${CHAKRACORE_BINARY_DIR}/)
target_link_libraries(ChakraCore
-Wl,-undefined,error
# -Wl,--start-group
# -Wl,--whole-archive
Chakra.Jsrt
Chakra.Jsrt.Core
# -Wl,--no-whole-archive
Chakra.Runtime.Types
Chakra.Runtime.Math
Chakra.Runtime.Library
Chakra.Runtime.Language
Chakra.Runtime.Debug
Chakra.Runtime.ByteCode
Chakra.Runtime.PlatformAgnostic
Chakra.Runtime.Base
Chakra.Parser
Chakra.Common.Util
Chakra.Common.Memory
Chakra.Common.Common
Chakra.Common.Core
Chakra.Common.DataStructures
Chakra.Common.Exceptions
Chakra.Common.Codex
# -Wl,--end-group
Chakra.Pal
pthread
stdc++
dl
icucore
# -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libChakraCoreLib.version
)
#
# Post build step to copy the built shared library
# to BuildLinux (or whatever the CMakeBuildDir is)
add_custom_command(TARGET ChakraCore POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CHAKRACORE_BINARY_DIR}/bin/ChakraCore/libChakraCore.dylib"
${CHAKRACORE_BINARY_DIR}/)
endif()
24 changes: 16 additions & 8 deletions bin/ch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ target_include_directories (ch
../../lib/Jsrt
)

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie")

target_link_libraries (ch
PRIVATE Chakra.Pal
PRIVATE Chakra.Common.Codex
PRIVATE Chakra.Runtime.PlatformAgnostic
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/ch.version
)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE")

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") # osx clang adds this by default
target_link_libraries (ch
PRIVATE Chakra.Pal
PRIVATE Chakra.Common.Codex
PRIVATE Chakra.Runtime.PlatformAgnostic
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/ch.version
)
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
target_link_libraries (ch
PRIVATE Chakra.Pal
PRIVATE Chakra.Common.Codex
PRIVATE Chakra.Runtime.PlatformAgnostic
)
endif()
# Add a post build event to the ch target
# which executes a command to copy ch to
# BuildLinux for convenience
Expand Down
4 changes: 4 additions & 0 deletions bin/ch/ChakraRtInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
LPCSTR chakraDllName = "chakracore.dll";
#else
#include <dlfcn.h>
#ifdef __APPLE__
LPCSTR chakraDllName = "libChakraCore.dylib";
#else
LPCSTR chakraDllName = "libChakraCore.so";
#endif
#endif

bool ChakraRTInterface::m_testHooksSetup = false;
bool ChakraRTInterface::m_testHooksInitialized = false;
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ if [[ ${#_CXX} > 0 ]]; then
CC_PREFIX="-DCMAKE_CXX_COMPILER=$_CXX -DCMAKE_C_COMPILER=$_CC"
fi

build_directory="$CHAKRACORE_DIR/BuildLinux/${BUILD_TYPE,,}"
build_directory="$CHAKRACORE_DIR/BuildLinux/${BUILD_TYPE:0}"
if [ ! -d "$build_directory" ]; then
SAFE_RUN `mkdir -p $build_directory`
fi
Expand Down
6 changes: 3 additions & 3 deletions lib/Runtime/Language/amd64/JavascriptOperatorsA.S
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
.intel_syntax noprefix
#include "unixasmmacros.inc"

// expected fvisibility=default
.global C_FUNC(amd64_CallWithFakeFrame)
.global C_FUNC(amd64_ReturnFromCallWithFakeFrame)

// r8 = arg0.
// rcx = args size.
// rdx = spill size.
Expand All @@ -22,7 +22,7 @@ C_FUNC(amd64_CallWithFakeFrame):
// The stack walker uses this marker to skip this frame.
// Note that we use rip-relative addressing here since this
// library is shared and therefore the code has to be position independent
lea rax, [rip+C_FUNC(amd64_ReturnFromCallWithFakeFrame)]
lea rax, [rip + C_FUNC(amd64_ReturnFromCallWithFakeFrame)]
mov [rsp+8h], rax

mov rax, [rsp + 28h]
Expand Down Expand Up @@ -57,9 +57,9 @@ C_FUNC(amd64_CallWithFakeFrame):

jmp rdi


// rcx = args size.
// rdx = spill size.

.balign 16
C_FUNC(amd64_ReturnFromCallWithFakeFrame):
add rsp, rcx
Expand Down
14 changes: 8 additions & 6 deletions lib/Runtime/Library/amd64/JavascriptFunctionA.S
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
.intel_syntax noprefix
#include "unixasmmacros.inc"

.extern C_FUNC(_ZN2Js18JavascriptFunction13DeferredParseEPPNS_14ScriptFunctionE)
.extern C_FUNC(_ZN2Js18JavascriptFunction19DeferredDeserializeEPNS_14ScriptFunctionE)

.global C_FUNC(_ZN2Js18JavascriptFunction20DeferredParsingThunkEPNS_16RecyclableObjectENS_8CallInfoEz)
.global C_FUNC(_ZN2Js18JavascriptFunction24DeferredDeserializeThunkEPNS_16RecyclableObjectENS_8CallInfoEz)

#ifndef __APPLE__
.extern _ZN2Js18JavascriptFunction13DeferredParseEPPNS_14ScriptFunctionE
.extern _ZN2Js18JavascriptFunction19DeferredDeserializeEPNS_14ScriptFunctionE

.type _ZN2Js18JavascriptFunction20DeferredParsingThunkEPNS_16RecyclableObjectENS_8CallInfoEz, @function
.type _ZN2Js18JavascriptFunction24DeferredDeserializeThunkEPNS_16RecyclableObjectENS_8CallInfoEz, @function
#endif
Expand Down Expand Up @@ -103,11 +103,12 @@ LOCAL_LABEL(function_done):
lea rsp, [rbp]
pop_nonvol_reg rbp
ret

NESTED_END amd64_CallFunction, _TEXT


// extrn ?DeferredParse@JavascriptFunction@Js@@SAP6APEAXPEAVRecyclableObject@2@UCallInfo@2@ZZPEAPEAVScriptFunction@2@@Z : PROC
.balign 16
.text
C_FUNC(_ZN2Js18JavascriptFunction20DeferredParsingThunkEPNS_16RecyclableObjectENS_8CallInfoEz):
push rbp
lea rbp, [rsp]
Expand All @@ -120,14 +121,15 @@ C_FUNC(_ZN2Js18JavascriptFunction20DeferredParsingThunkEPNS_16RecyclableObjectEN
// JavascriptMethod JavascriptFunction::DeferredParse(ScriptFunction**)
//
lea rdi, [rbp + 10h] // &function, setup by custom calling convention
call C_PLTFUNC(_ZN2Js18JavascriptFunction13DeferredParseEPPNS_14ScriptFunctionE)
call C_FUNC(_ZN2Js18JavascriptFunction13DeferredParseEPPNS_14ScriptFunctionE)

pop rsi
pop rdi
pop rbp

jmp rax


// Var JavascriptFunction::DeferredDeserializeThunk(
// RecyclableObject* function, CallInfo callInfo, ...)
.balign 16
Expand All @@ -144,7 +146,7 @@ C_FUNC(_ZN2Js18JavascriptFunction24DeferredDeserializeThunkEPNS_16RecyclableObje
// ScriptFunction* function)
//
// RDI == function, setup by custom calling convention
call C_PLTFUNC(_ZN2Js18JavascriptFunction19DeferredDeserializeEPNS_14ScriptFunctionE)
call C_FUNC(_ZN2Js18JavascriptFunction19DeferredDeserializeEPNS_14ScriptFunctionE)

pop rsi
pop rdi
Expand Down
11 changes: 5 additions & 6 deletions lib/Runtime/PlatformAgnostic/Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
project(CHAKRA_PLATFORM_AGNOSTIC)

check_function_exists(gmtime_r HAVE_GMTIME_R)

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
add_library (Chakra.Runtime.PlatformAgnostic
Linux/UnicodeText.ICU.cpp
Expand All @@ -13,14 +11,15 @@ add_library (Chakra.Runtime.PlatformAgnostic
)
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
add_library (Chakra.Runtime.PlatformAgnostic
#Linux/UnicodeText.ICU.cpp
#Linux/DateTime.cpp
#Linux/HiResTimer.cpp
# xplat-todo: implement them for unix! or carry them into common
Linux/UnicodeText.ICU.cpp
Linux/DateTime.cpp
Linux/HiResTimer.cpp
Linux/NumbersUtility.cpp
Unix/SystemInfo.cpp
Common/UnicodeText.Common.cpp
)
endif()


target_include_directories (
Chakra.Runtime.PlatformAgnostic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
1 change: 0 additions & 1 deletion pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ extern "C" {

#endif

#include <pal_char16.h>
#include <pal_error.h>
#include <pal_mstypes.h>

Expand Down
53 changes: 0 additions & 53 deletions pal/inc/pal_char16.h

This file was deleted.

Loading

0 comments on commit 807ed43

Please sign in to comment.