Skip to content

Commit 3cf244f

Browse files
committed
cross-platform: macOS dylib (shared library) support [passing all the tests]
1 parent 8f9d334 commit 3cf244f

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

bin/ChakraCore/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux)
3232
-Wl,--no-whole-archive
3333
-Wl,--end-group
3434
)
35+
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
36+
set(LINKER_START_GROUP -Wl,-force_load,)
3537
endif()
3638

3739
# common link deps

bin/ChakraCore/ChakraCoreDllFunc.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
#include "Base/VTuneChakraProfile.h"
1717
#endif
1818

19+
#ifdef __APPLE__
20+
// dummy usage of JSRT to force export JSRT on dylib
21+
#include "ChakraCore.h"
22+
void DummyJSRTCall() {
23+
JsRuntimeHandle *runtime;
24+
JsRuntimeAttributes attr;
25+
JsCreateRuntime(attr, nullptr, runtime);
26+
}
27+
#endif
28+
1929
extern HANDLE g_hInstance;
2030
#ifdef _WIN32
2131
static ATOM lockedDll = 0;
@@ -61,7 +71,7 @@ static BOOL AttachProcess(HANDLE hmod)
6171
#endif
6272
#ifdef VTUNE_PROFILING
6373
VTuneChakraProfile::Register();
64-
#endif
74+
#endif
6575
ValueType::Initialize();
6676
ThreadContext::GlobalInitialize();
6777

@@ -166,7 +176,7 @@ EXTERN_C BOOL WINAPI DllMain(HINSTANCE hmod, DWORD dwReason, PVOID pvReserved)
166176
#endif
167177
#ifdef VTUNE_PROFILING
168178
VTuneChakraProfile::UnRegister();
169-
#endif
179+
#endif
170180

171181
// don't do anything if we are in forceful shutdown
172182
// try to clean up handles in graceful shutdown

lib/Jsrt/ChakraCommon.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,16 @@ typedef BYTE* ChakraBytePtr;
6161
#define CHAKRA_CALLBACK
6262
#endif // __i386__
6363

64+
#ifndef _WIN32
65+
#define SET_API_VISIBILITY __attribute__((visibility("default")))
66+
#else
67+
#define SET_API_VISIBILITY
68+
#endif
69+
6470
#ifdef __cplusplus
65-
#define CHAKRA_API extern "C" JsErrorCode
71+
#define CHAKRA_API SET_API_VISIBILITY extern "C" JsErrorCode
6672
#else
67-
#define CHAKRA_API JsErrorCode
73+
#define CHAKRA_API SET_API_VISIBILITY extern JsErrorCode
6874
#endif
6975

7076
#include <stddef.h> // for size_t

0 commit comments

Comments
 (0)