Skip to content

Commit 196ceeb

Browse files
committed
cross-platform: xcode project support
disclaimer: xcode project support should be considered as a community feature. At the moment, it is not officially supported. Implements generating xcode project using ChakraCore's build script and fixes compile time issues with xcode.
1 parent b942fdb commit 196ceeb

6 files changed

Lines changed: 66 additions & 38 deletions

File tree

CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,19 @@ if(CLR_CMAKE_PLATFORM_UNIX)
8484
# prevent the required interface is being exported
8585
# clang by default sets fvisibility=default
8686

87+
if(NOT CC_XCODE_PROJECT)
88+
# todo: enable for XCode too
89+
# XCode is a bit more strict
90+
# keep this until we fix all the warnings there.
91+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
92+
-Werror"
93+
)
94+
endif()
95+
8796
# CXX WARNING FLAGS
8897
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
89-
-Werror\
98+
-Wno-missing-braces\
99+
-Wno-reorder\
90100
-Wno-microsoft\
91101
-Wno-unused-value\
92102
-Wno-int-to-void-pointer-cast\
@@ -175,7 +185,6 @@ include_directories(
175185
${ICU_INCLUDE_PATH}
176186
)
177187

178-
179188
add_subdirectory (pal)
180189

181190
# build the rest with NO_PAL_MINMAX and PAL_STDCPP_COMPAT

bin/ChakraCore/CMakeLists.txt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux)
6060
icuuc
6161
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libChakraCoreLib.version
6262
)
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}/)
7063
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
7164
# todo: combine link libraries into a list
7265
# reminder: order of the link libraries matters
@@ -105,11 +98,19 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
10598
icucore
10699
# -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libChakraCoreLib.version
107100
)
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}/)
101+
endif()
102+
103+
if(NOT CC_XCODE_PROJECT)
104+
set(CC_LIB_EXT "so")
105+
# Post build step to copy the built shared library
106+
# to BuildLinux (or whatever the CMakeBuildDir is)
107+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
108+
set(CC_LIB_EXT "dylib")
109+
endif()
110+
111+
add_custom_command(TARGET ChakraCore POST_BUILD
112+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
113+
"${CHAKRACORE_BINARY_DIR}/bin/ChakraCore/libChakraCore.${CC_LIB_EXT}"
114+
${CHAKRACORE_BINARY_DIR}/
115+
)
115116
endif()

bin/ch/CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
3939
PRIVATE Chakra.Runtime.PlatformAgnostic
4040
)
4141
endif()
42-
# Add a post build event to the ch target
43-
# which executes a command to copy ch to
44-
# BuildLinux for convenience
45-
add_custom_command(TARGET ch POST_BUILD
46-
COMMAND ${CMAKE_COMMAND} -E copy_if_different
47-
"${CHAKRACORE_BINARY_DIR}/bin/ch/ch"
48-
${CHAKRACORE_BINARY_DIR}/)
42+
43+
if(NOT CC_XCODE_PROJECT)
44+
# Add a post build event to the ch target
45+
# which executes a command to copy ch to
46+
# BuildLinux for convenience
47+
add_custom_command(TARGET ch POST_BUILD
48+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
49+
"${CHAKRACORE_BINARY_DIR}/bin/ch/ch"
50+
${CHAKRACORE_BINARY_DIR}/)
51+
endif()

build.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ PRINT_USAGE() {
2727
echo " --icu=PATH Path to ICU include folder (see example below)"
2828
echo " -j [N], --jobs[=N] Multicore build, allow N jobs at once"
2929
echo " -n, --ninja Build with ninja instead of make"
30+
echo " --xcode Generate XCode project"
3031
echo " -t, --test-build Test build (by default Release build)"
3132
echo " -v, --verbose Display verbose output including all options"
3233
echo ""
@@ -104,6 +105,11 @@ while [[ $# -gt 0 ]]; do
104105
MAKE=ninja
105106
;;
106107

108+
--xcode)
109+
CMAKE_GEN="-G Xcode -DCC_XCODE_PROJECT=1"
110+
MAKE=0
111+
;;
112+
107113
*)
108114
echo "Unknown option $1"
109115
PRINT_USAGE
@@ -186,5 +192,12 @@ pushd $build_directory > /dev/null
186192
echo Generating $BUILD_TYPE makefiles
187193
cmake $CMAKE_GEN $CC_PREFIX $ICU_PATH -DCMAKE_BUILD_TYPE=$BUILD_TYPE ../..
188194

189-
$MAKE $MULTICORE_BUILD 2>&1 | tee build.log
195+
if [[ $? == 0 ]]; then
196+
if [[ $MAKE != 0 ]]; then
197+
$MAKE $MULTICORE_BUILD 2>&1 | tee build.log
198+
else
199+
echo "Visit given folder above for xcode project file ----^"
200+
fi
201+
fi
202+
190203
popd > /dev/null

lib/Runtime/Library/JavascriptLibrary.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ namespace Js
165165
static DWORD GetCharStringCacheOffset() { return offsetof(JavascriptLibrary, charStringCache); }
166166
static DWORD GetCharStringCacheAOffset() { return GetCharStringCacheOffset() + CharStringCache::GetCharStringCacheAOffset(); }
167167
const JavascriptLibraryBase* GetLibraryBase() const { return static_cast<const JavascriptLibraryBase*>(this); }
168-
void SetGlobalObject(GlobalObject* globalObject) {globalObject = globalObject; }
168+
void SetGlobalObject(GlobalObject* globalObject) {this->globalObject = globalObject; }
169169
static DWORD GetRandSeed0Offset() { return offsetof(JavascriptLibrary, randSeed0); }
170170
static DWORD GetRandSeed1Offset() { return offsetof(JavascriptLibrary, randSeed1); }
171171

@@ -520,7 +520,7 @@ namespace Js
520520
bindRefChunkEnd(nullptr),
521521
dynamicFunctionReference(nullptr)
522522
{
523-
globalObject = globalObject;
523+
this->globalObject = globalObject;
524524
}
525525

526526
void Initialize(ScriptContext* scriptContext, GlobalObject * globalObject);

pal/src/cruntime/misc.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -445,24 +445,26 @@ char *MiscGetenv(const char *name)
445445
InternalEnterCriticalSection(pthrCurrent, &gcsEnvironment);
446446

447447
length = strlen(name);
448-
for(i = 0; palEnvironment[i] != NULL; i++)
448+
if (palEnvironment)
449449
{
450-
if (memcmp(palEnvironment[i], name, length) == 0)
450+
for(i = 0; palEnvironment[i] != NULL; i++)
451451
{
452-
equals = palEnvironment[i] + length;
453-
if (*equals == '\0')
454-
{
455-
pRet = (char *) "";
456-
goto done;
457-
}
458-
else if (*equals == '=')
452+
if (memcmp(palEnvironment[i], name, length) == 0)
459453
{
460-
pRet = equals + 1;
461-
goto done;
454+
equals = palEnvironment[i] + length;
455+
if (*equals == '\0')
456+
{
457+
pRet = (char *) "";
458+
goto done;
459+
}
460+
else if (*equals == '=')
461+
{
462+
pRet = equals + 1;
463+
goto done;
464+
}
462465
}
463466
}
464467
}
465-
466468
done:
467469
InternalLeaveCriticalSection(pthrCurrent, &gcsEnvironment);
468470
return pRet;

0 commit comments

Comments
 (0)