Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cross-platform, cross-compile build toolchain #280

Merged
merged 25 commits into from
Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9686139
added CMake build scripts (replaces VS .sln)
drywolf Feb 22, 2017
b57b921
changed NodeJS dependency default path
drywolf Feb 22, 2017
d89202e
Merge remote-tracking branch 'upstream/master'
drywolf May 3, 2017
9c75430
MacOS build working (some Node.js tests failing)
drywolf May 12, 2017
45e487d
Merge remote-tracking branch 'upstream/master'
drywolf May 12, 2017
bf02e87
MacOS linking fix & script cleanups
drywolf May 13, 2017
076ffe2
split up python build-scripts
drywolf May 13, 2017
f3e69cc
moved python build utils to separate directory
drywolf May 13, 2017
6d2bbb8
split cmake generation and jni compile
drywolf May 13, 2017
1ff1de4
updated win32 node link libs (node v7.4.0+)
drywolf May 14, 2017
54fdc43
fixed win32 build for 7.4.0 + module linking sanity checks
drywolf May 14, 2017
d0deb23
win32 build-steps config
drywolf May 15, 2017
3954205
adding android build support
drywolf May 16, 2017
18c7b37
android builds working (arm & x86) ... no automatic bundling yet
drywolf May 21, 2017
9cd7c6a
linux build support, android fixes & build-output reuse
drywolf May 29, 2017
7f2e8cf
docker android testing support
drywolf Jun 3, 2017
2f66df8
fixed hardcoded build_cwd for node.js build artifact reuse
drywolf Jun 4, 2017
9e45f55
fixed all open TODOs & refactored build-system code
drywolf Jun 11, 2017
8297dab
added some more build-system features & utils
drywolf Jun 14, 2017
63ac9d1
build-system refactoring & code cleanups
drywolf Jun 15, 2017
da5d322
Merge remote-tracking branch 'upstream/master'
drywolf Jun 15, 2017
de97277
updated build documentation in README.md
drywolf Jun 15, 2017
80f16de
improved --help message & fixed macos native lib copy
drywolf Jun 15, 2017
9359bb8
fixes based on feedback in PR #280 by matiwinnetou
drywolf Jun 20, 2017
d339049
Merge remote-tracking branch 'upstream/master'
drywolf Jun 20, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ hs_err*.log
*.iws
.idea

# python binaries
*.pyc

# Build output.
node
cmake.out
109 changes: 65 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,60 +1,64 @@
cmake_minimum_required (VERSION 2.6)
project (j2v8)
cmake_minimum_required(VERSION 2.6)
project(j2v8)

# adding cmake directory for includes
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

include (BuildUtils)
include (NodeJsUtils)
include (Policies)
# set up the module path
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

include(BuildUtils)
include(NodeJsUtils)
include(Policies)

#-----------------------------------------------------------------------
# CMAKE OPTIONS
# BUILD PLATFORM SETUP & VARIABLES
#-----------------------------------------------------------------------
option(J2V8_NODE_COMPATIBLE "Build the J2V8 native bridge with Node.js support enabled" ON)
option(J2V8_BUILD_ONLY_DEBUG_RELEASE "Generate only Debug and Release configurations (exclude RelWithDebInfo and MinSizeRel)" ON)

# set up the module path
set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

# remove the MinSizeRel and RelWithDebInfo configurations
if (J2V8_BUILD_ONLY_DEBUG_RELEASE)
#{
set (CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "limited configs" FORCE)
#}
endif ()
if(APPLE)
set(JAVA_PLATFORM_NAME "darwin")
set(J2V8_LIB_PLATFORM_NAME "macosx")
set(J2V8_LIB_PREFIX "")
elseif(WIN32)
set(JAVA_PLATFORM_NAME "win32")
set(J2V8_LIB_PLATFORM_NAME "win32")
set(J2V8_LIB_PREFIX "lib")
endif()

#-----------------------------------------------------------------------
# DEPENDENCY SETTINGS & DISCOVERY
# DEPENDENCY SETTINGS / CMAKE OPTIONS
#-----------------------------------------------------------------------

# look for dependencies
find_package(Java)

# overridable settings
set (J2V8_JDK_DIR ${Java_ROOT} CACHE STRING "Path to the Java JDK dependency")
set (J2V8_NODEJS_DIR "${CMAKE_SOURCE_DIR}/../node" CACHE STRING "Path to the Node.js dependency")
# j2v8 dependency options
set(J2V8_JDK_DIR ${Java_ROOT} CACHE STRING "Path to the Java JDK dependency")
set(J2V8_NODEJS_DIR "${CMAKE_SOURCE_DIR}/node" CACHE STRING "Path to the Node.js dependency")

# get lists of the required Node.js link libraries
get_njs_libs (${J2V8_NODEJS_DIR} "Debug")
get_njs_libs (${J2V8_NODEJS_DIR} "Release")
# get the required Node.js link libraries
get_njs_libs(${J2V8_NODEJS_DIR} "Debug")
get_njs_libs(${J2V8_NODEJS_DIR} "Release")

# j2v8 build options
option(J2V8_NODE_COMPATIBLE "Build the J2V8 native bridge with Node.js support enabled" ON)
option(J2V8_BUILD_ONLY_DEBUG_RELEASE "Generate only Debug and Release configurations (exclude RelWithDebInfo and MinSizeRel)" ON)

#-----------------------------------------------------------------------
# INCLUDE DIRECTORIES & SOURCE FILES
#-----------------------------------------------------------------------

# project include directories
set (include_dirs
set(include_dirs
${J2V8_JDK_DIR}/include
${J2V8_JDK_DIR}/include/win32
${J2V8_JDK_DIR}/include/${JAVA_PLATFORM_NAME}
${J2V8_NODEJS_DIR}
${J2V8_NODEJS_DIR}/src
${J2V8_NODEJS_DIR}/deps/v8
${J2V8_NODEJS_DIR}/deps/v8/include
)

# project source files
set (src_files
set(src_files
jni/com_eclipsesource_v8_V8Impl.cpp
jni/com_eclipsesource_v8_V8Impl.h
)
Expand All @@ -65,26 +69,41 @@ source_group("" FILES ${src_files})
# BUILD SETTINGS & COMPILATION
#-----------------------------------------------------------------------

link_static_crt()
# tell gcc/clang to use the c++11 standard
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
endif()

# remove the MinSizeRel and RelWithDebInfo configurations
if(J2V8_BUILD_ONLY_DEBUG_RELEASE)
#{
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "limited configs" FORCE)
#}
endif()

# link against the static MS C++ runtime libraries
if(MSVC)
link_static_crt()
endif()

# create the j2v8 library
add_library (j2v8 SHARED ${src_files})
add_library(j2v8 SHARED ${src_files})

# enable Node.js if requested by the set options
if (J2V8_NODE_COMPATIBLE)
# enable Node.js if requested by the build options above
if(J2V8_NODE_COMPATIBLE)
#{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are curly braces commented out?

Copy link
Contributor Author

@drywolf drywolf Jul 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use those just by convention to make it easier for the eye to quickly read where the scope of a if-elif-else block starts and ends. This being said, for the next PR I have removed those where only a single line is inside the branch scope. From now on they are only used for if-elif-else blocks that contain multiple lines in their respective blocks (which was the original intent). Thanks for the feedback

set_property (TARGET j2v8 PROPERTY COMPILE_DEFINITIONS ${COMPILE_DEFINITIONS} NODE_COMPATIBLE=1)
set_property(TARGET j2v8 PROPERTY COMPILE_DEFINITIONS ${COMPILE_DEFINITIONS} NODE_COMPATIBLE=1)
#}
endif ()
endif()

# build output directory
set (LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)

# set the include directories
include_directories (${include_dirs})
include_directories(${include_dirs})

# link the necessary libraries
target_link_libraries (j2v8
target_link_libraries(j2v8
debug "${njs_Debug_libs}"
optimized "${njs_Release_libs}"
)
Expand All @@ -93,15 +112,17 @@ target_link_libraries (j2v8
# OUTPUT SETTINGS & POST-BUILD
#-----------------------------------------------------------------------

if (CMAKE_CL_64)
set (ARCH_SUFFIX "_64")
endif ()
# apply lib suffix if building a 64 bit target
if(CMAKE_CL_64 OR CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCH_SUFFIX "_64")
endif()

set_target_properties (j2v8 PROPERTIES OUTPUT_NAME "${PROJECT_NAME}_win32_x86${ARCH_SUFFIX}")
# set library output filename
set_target_properties(j2v8 PROPERTIES OUTPUT_NAME "${PROJECT_NAME}_${J2V8_LIB_PLATFORM_NAME}_x86${ARCH_SUFFIX}")

# copy native lib to Java project resources directory
add_custom_command (TARGET j2v8 POST_BUILD
# copy native lib to J2V8 project resources directory
add_custom_command(TARGET j2v8 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:j2v8>
${CMAKE_SOURCE_DIR}/src/main/resources/lib$<TARGET_FILE_NAME:j2v8>
${CMAKE_SOURCE_DIR}/src/main/resources/${J2V8_LIB_PREFIX}$<TARGET_FILE_NAME:j2v8>
)
26 changes: 26 additions & 0 deletions build_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import build_platform as b

# b.execute_build(b.target_macos, b.arch_x86, b.build_all, node_enabled = True, cross_compile = True)
b.execute_build(b.target_macos, b.arch_x64, b.build_all, node_enabled = True, cross_compile = True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't node_enabled set in the cmake file? Why is it set here too?

Copy link
Contributor Author

@drywolf drywolf Jul 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way command-line switches and arguments are translated to changes in the produced binary build artifacts is (roughly) as follows:

--node-enabled --> params.node_enabled --> J2V8_NODE_ENABLED --> NODE_COMPATIBLE=1

  • --node-enabled // passed via the build.py CLI
    • is parsed in the python code and turned into a boolean variable + value
  • params.node_enabled // variable in python containing the parsed boolean value
    • is put into a "config" dictionary/object that will be passed as a parameter to each build-step function for the build
    • each build-step can decide to access the variable and do something with it
  • J2V8_NODE_ENABLED // the CMakeLists.txt file exposes this boolean variable that can be overridden when invoking the cmake CLI
    • the def build_j2v8_cmake(config): build-step passes the value of the "config" object property node_enabled to the cmake CLI when it is invoked in this build-step
  • NODE_COMPATIBLE=1 // if the above CMake variable is set "TRUE"
    • this compiler preprocessor-definition will be included when generating the native build files

Having said that, the above code of build_all.py is just using the way to skip over the first step of the chain shown above, and directly pass a user-specified configuration to the python function that then continues to process the build in the same way as if it was originally called from the CLI.

PS: in the next PR the code from build_all.py will be moved to build_configs.py


# b.execute_build(b.target_linux, b.arch_x64, b.build_all, True, True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are most of the lines in this file commented out?

Copy link
Contributor Author

@drywolf drywolf Jul 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used this file mostly for testing during the early build-system development, in the next PR this will be more fleshed out and become a feature to run an interactive CLI and choose from a set of pre-configured build-configurations


# build Node.js only
# def build_njs(target, arch):
# b.execute_build(target, arch, [b.build_node_js], node_enabled = True, cross_compile = True)

# build_njs(b.target_android, b.arch_arm)
# build_njs(b.target_android, b.arch_x86)

# build_njs(b.target_linux, b.arch_x86)
# build_njs(b.target_linux, b.arch_x64)

# # needs reboot here to turn Hyper-V off if Host-OS is Windows

# build_njs(b.target_macos, b.arch_x86)
# build_njs(b.target_macos, b.arch_x64)

# # needs reboot here to switch to Windows-Containers

# build_njs(b.target_win32, b.arch_x86)
# build_njs(b.target_win32, b.arch_x64)
Loading