Skip to content

Commit

Permalink
feat: add option to build quickjs as static library (openkraken#1022)
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall authored Dec 27, 2021
1 parent 556a9de commit e8a38e3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
23 changes: 15 additions & 8 deletions bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ if ($ENV{KRAKEN_JS_ENGINE} MATCHES "quickjs")
${CMAKE_CURRENT_SOURCE_DIR}/third_party/quickjs/quickjs-atom.h
${CMAKE_CURRENT_SOURCE_DIR}/third_party/quickjs/quickjs-opcode.h
)
add_library(quickjs SHARED ${QUICK_JS_SOURCE})
if(${STATIC_QUICKJS})
add_library(quickjs STATIC ${QUICK_JS_SOURCE})
else()
add_library(quickjs SHARED ${QUICK_JS_SOURCE})
endif()

list(APPEND BRIDGE_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
list(APPEND BRIDGE_LINK_LIBS quickjs)
Expand Down Expand Up @@ -365,11 +369,14 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "iOS")
PUBLIC_HEADER ${KRAKEN_PUBLIC_HEADERS}
)

set_target_properties(quickjs PROPERTIES
OUTPUT_NAME quickjs
FRAMEWORK TRUE
FRAMEWORK_VERSION C
MACOSX_FRAMEWORK_IDENTIFIER com.openkraken.quickjs
PUBLIC_HEADER ${QUICKJS_PUBLIC_HEADERS}
)
# If quickjs is static, there will be no quickjs.framework any more.
if(NOT ${STATIC_QUICKJS})
set_target_properties(quickjs PROPERTIES
OUTPUT_NAME quickjs
FRAMEWORK TRUE
FRAMEWORK_VERSION C
MACOSX_FRAMEWORK_IDENTIFIER com.openkraken.quickjs
PUBLIC_HEADER ${QUICKJS_PUBLIC_HEADERS}
)
endif()
endif ()
35 changes: 26 additions & 9 deletions scripts/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const del = require('del');
const os = require('os');

program
.option('--built-with-debug-jsc', 'Built bridge binary with debuggable JSC.')
.option('--static-quickjs', 'Build quickjs as static library and bundled into kraken library.', false)
.parse(process.argv);

const SUPPORTED_JS_ENGINES = ['jsc', 'quickjs'];
Expand Down Expand Up @@ -182,8 +182,6 @@ task('build-darwin-kraken-lib', done => {
buildType = 'RelWithDebInfo';
}

let builtWithDebugJsc = targetJSEngine === 'jsc' && !!program.builtWithDebugJsc;

if (isProfile) {
externCmakeArgs.push('-DENABLE_PROFILE=TRUE');
}
Expand All @@ -192,9 +190,9 @@ task('build-darwin-kraken-lib', done => {
externCmakeArgs.push('-DENABLE_ASAN=true');
}

if (builtWithDebugJsc) {
let debugJsEngine = findDebugJSEngine(platform == 'darwin' ? 'macos' : platform);
externCmakeArgs.push(`-DDEBUG_JSC_ENGINE=${debugJsEngine}`)
// Bundle quickjs into kraken.
if (program.staticQuickjs) {
externCmakeArgs.push('-DSTATIC_QUICKJS=true');
}

execSync(`cmake -DCMAKE_BUILD_TYPE=${buildType} -DENABLE_TEST=true ${externCmakeArgs.join(' ')} \
Expand Down Expand Up @@ -432,6 +430,11 @@ task(`build-ios-kraken-lib`, (done) => {
externCmakeArgs.push('-DENABLE_ASAN=true');
}

// Bundle quickjs into kraken.
if (program.staticQuickjs) {
externCmakeArgs.push('-DSTATIC_QUICKJS=true');
}

// generate build scripts for simulator
execSync(`cmake -DCMAKE_BUILD_TYPE=${buildType} \
-DCMAKE_TOOLCHAIN_FILE=${paths.bridge}/cmake/ios.toolchain.cmake \
Expand Down Expand Up @@ -476,7 +479,7 @@ task(`build-ios-kraken-lib`, (done) => {
execSync(`cmake --build ${paths.bridge}/cmake-build-ios-arm --target kraken kraken_static -- -j 12`, {
stdio: 'inherit'
});

// Generate builds scripts for ARMv7s, ARMv7
execSync(`cmake -DCMAKE_BUILD_TYPE=${buildType} \
-DCMAKE_TOOLCHAIN_FILE=${paths.bridge}/cmake/ios.toolchain.cmake \
Expand All @@ -499,7 +502,12 @@ task(`build-ios-kraken-lib`, (done) => {
stdio: 'inherit'
});

const targetSourceFrameworks = ['kraken_bridge', 'quickjs'];
const targetSourceFrameworks = ['kraken_bridge'];

// If quickjs is not static, there will be another framework called quickjs.framework.
if (!program.staticQuickjs) {
targetSourceFrameworks.push('quickjs');
}

targetSourceFrameworks.forEach(target => {
const armDynamicSDKPath = path.join(paths.bridge, `build/ios/lib/arm/${target}.framework`);
Expand Down Expand Up @@ -623,12 +631,21 @@ task('build-android-kraken-lib', (done) => {
externCmakeArgs.push('-DENABLE_ASAN=true');
}

// Bundle quickjs into kraken.
if (program.staticQuickjs) {
externCmakeArgs.push('-DSTATIC_QUICKJS=true');
}

const soFileNames = [
'libkraken',
'libquickjs',
'libc++_shared'
];

// If quickjs is not static, there will be another so called libquickjs.so.
if (!program.staticQuickjs) {
soFileNames.push('libquickjs');
}

const cmakeGeneratorTemplate = platform == 'win32' ? 'Ninja' : 'Unix Makefiles';
archs.forEach(arch => {
const soBinaryDirectory = path.join(paths.bridge, `build/android/lib/${arch}`);
Expand Down

0 comments on commit e8a38e3

Please sign in to comment.