Skip to content

Commit

Permalink
[GR-30461] [GR-30463] [GR-30462] Sulong: build libraries using ninja.
Browse files Browse the repository at this point in the history
PullRequest: graal/8673
  • Loading branch information
zapster committed Apr 12, 2021
2 parents 4a3a4e7 + 61e3387 commit 836d28b
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 190 deletions.
27 changes: 24 additions & 3 deletions sulong/mx.sulong/mx_sulong_suite_constituents.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ def getBuildTask(self, args):
def isPlatformDependent(self):
return True

def getJavaProperties(self, replaceVar=mx_subst.path_substitutions):
ret = {}
if hasattr(self, "javaProperties"):
for key, value in self.javaProperties.items():
ret[key] = replaceVar.substitute(value, dependency=self)
return ret


def _quote_windows(arg):
return '"{}"'.format(arg)
Expand Down Expand Up @@ -450,7 +457,12 @@ def contents(self, tool, exe):
classpath_deps = [dep for dep in self.subject.buildDependencies if isinstance(dep, mx.ClasspathDependency)]
extra_props = ['-Dorg.graalvm.launcher.executablename="{}"'.format(exe)]
main_class = self.subject.suite.toolchain._tool_to_main(tool)
# add jvm args from dependencies
jvm_args = [_quote(arg) for arg in mx.get_runtime_jvm_args(classpath_deps)]
# add properties from the project
if hasattr(self.subject, "getJavaProperties"):
for key, value in sorted(self.subject.getJavaProperties().items()):
jvm_args.append("-D" + key + "=" + value)
command = [java] + jvm_args + extra_props + [main_class, all_params]
# create script
if mx.is_windows():
Expand All @@ -469,12 +481,18 @@ def check_cmake():

@staticmethod
def run_cmake(cmdline, silent, *args, **kwargs):
log_error = kwargs.pop("log_error", False)
if mx._opts.verbose:
mx.run(["cmake"] + cmdline, *args, **kwargs)
else:
with open(os.devnull, 'w') as fnull:
err = fnull if silent else None
mx.run(["cmake"] + cmdline, out=fnull, err=err, *args, **kwargs)
err = mx.OutputCapture() if silent else None
try:
mx.run(["cmake"] + cmdline, out=fnull, err=err, *args, **kwargs)
except:
if log_error and err and err.data:
mx.log_error(err.data)
raise


class CMakeBuildTaskMixin(object):
Expand All @@ -497,10 +515,13 @@ def _guard_data(self, source_dir, cmake_config):

def _need_configure(self):
source_dir = self.subject.source_dirs()[0]
cmake_lists = os.path.join(source_dir, "CMakeLists.txt")
guard_file = self.guard_file()
cmake_config = self.subject.cmake_config()
if not os.path.exists(guard_file):
return True, "No CMake configuration found - reconfigure"
if os.path.exists(cmake_lists) and mx.TimeStampFile(cmake_lists).isNewerThan(mx.TimeStampFile(guard_file)):
return True, cmake_lists + " is newer than the configuration - reconfigure"
with open(guard_file, 'r') as fp:
if fp.read() != self._guard_data(source_dir, cmake_config):
return True, "CMake configuration changed - reconfigure"
Expand Down Expand Up @@ -674,7 +695,7 @@ def generate_manifest(self, path):
# cmake will always create build.ninja - there is nothing we can do about it ATM
cmdline = ["-G", "Ninja", source_dir] + cmake_config
CMakeSupport.check_cmake()
CMakeSupport.run_cmake(cmdline, silent=True, cwd=out_dir)
CMakeSupport.run_cmake(cmdline, silent=True, cwd=out_dir, log_error=True)
# move the build.ninja to the temporary path (just move it back later ... *sigh*)
shutil.copyfile(os.path.join(out_dir, mx_native.Ninja.default_manifest), path)
return True
Expand Down
123 changes: 80 additions & 43 deletions sulong/mx.sulong/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,20 @@
"license" : "BSD-new",
},

"bootstrap-toolchain-launchers-no-home": {
"subDir": "projects",
"class" : "BootstrapToolchainLauncherProject",
"buildDependencies" : [
"sdk:LLVM_TOOLCHAIN",
"com.oracle.truffle.llvm.toolchain.launchers",
],
"javaProperties" : {
# we intentionally set llvm home to a non-existent location to avoid picking up outdated files
"org.graalvm.language.llvm.home" : "<path:SULONG_BOOTSTRAP_TOOLCHAIN_NO_HOME>/nonexistent",
},
"license" : "BSD-new",
},

"toolchain-launchers-tests": {
"subDir": "tests",
"native": True,
Expand Down Expand Up @@ -599,32 +613,34 @@
},
"com.oracle.truffle.llvm.libraries.bitcode" : {
"subDir" : "projects",
"native" : True,
"class" : "CMakeNinjaProject",
# NinjaBuildTask uses only 1 job otherwise
"max_jobs" : "8",
"vpath" : True,
"ninja_targets" : [
"<lib:sulong>",
"<lib:sulong++>",
],
"ninja_install_targets" : ["install"],
"results" : [
"bin/<lib:sulong>",
"bin/<lib:sulong++>",
],
"buildDependencies" : [
"com.oracle.truffle.llvm.libraries.graalvm.llvm",
"sdk:LLVM_TOOLCHAIN",
"sdk:LLVM_ORG_SRC",
"SULONG_BOOTSTRAP_TOOLCHAIN_NO_HOME",
"NATIVE_MODE_SUPPORT",
],
"buildEnv" : {
"CFLAGS" : "-Xclang -disable-O0-optnone -DOS_<os> -DARCH_<arch>",
"CPPFLAGS" : "-I<path:com.oracle.truffle.llvm.libraries.graalvm.llvm>/include",
"CLANG" : "<path:LLVM_TOOLCHAIN>/bin/clang",
"CLANGXX" : "<path:LLVM_TOOLCHAIN>/bin/clang++",
"OPT" : "<path:LLVM_TOOLCHAIN>/bin/opt",
"LLVM_LINK" : "<path:LLVM_TOOLCHAIN>/bin/llvm-link",
"LLVM_TOOLCHAIN_LIB" : "<path:LLVM_TOOLCHAIN>/lib",
"LIBSULONG" : "<lib:sulong>",
"LIBSULONGXX" : "<lib:sulong++>",
"LIBCXX_SRC" : "<path:sdk:LLVM_ORG_SRC>",
"OS" : "<os>",
},

"cmakeConfig" : {
"CMAKE_OSX_DEPLOYMENT_TARGET" : "10.11",
"CMAKE_C_COMPILER" : "<path:SULONG_BOOTSTRAP_TOOLCHAIN_NO_HOME>/bin/clang",
"CMAKE_CXX_COMPILER" : "<path:SULONG_BOOTSTRAP_TOOLCHAIN_NO_HOME>/bin/clang++",
"GRAALVM_LLVM_INCLUDE_DIR" : "<path:com.oracle.truffle.llvm.libraries.graalvm.llvm>/include",
"LIBCXX_SRC" : "<path:sdk:LLVM_ORG_SRC>",
"MX_OS" : "<os>",
"MX_ARCH" : "<arch>",
},
"license" : "BSD-new",
},
"com.oracle.truffle.llvm.libraries.graalvm.llvm" : {
Expand All @@ -647,43 +663,56 @@
},
"com.oracle.truffle.llvm.libraries.graalvm.llvm.libs" : {
"subDir" : "projects",
"native" : True,
"class" : "CMakeNinjaProject",
# NinjaBuildTask uses only 1 job otherwise
"max_jobs" : "8",
"vpath" : True,
"ninja_targets" : [
"<libv:graalvm-llvm.1>",
],
"ninja_install_targets" : ["install"],
"results" : [
# "bin/<lib:graalvm-llvm>",
# We on purpose exclude the symlink from the results because the layout distribution would dereference it and
# create a copy instead of keeping the symlink.
# The symlink is added manually in the layout definition of the distribution.
"bin/<libv:graalvm-llvm.1>",
],
"buildDependencies" : [
"SULONG_TOOLCHAIN_LAUNCHERS",
"SULONG_BOOTSTRAP_TOOLCHAIN",
"SULONG_BOOTSTRAP_TOOLCHAIN_NO_HOME",
"com.oracle.truffle.llvm.libraries.graalvm.llvm",
"NATIVE_MODE_SUPPORT",
],
"buildEnv" : {
"SONAME" : "<libv:graalvm-llvm.1>",
"CLANG" : "<toolchainGetToolPath:native,CC>",
"CPPFLAGS" : "-I<path:com.oracle.truffle.llvm.libraries.graalvm.llvm>/include",
"OS" : "<os>",
"cmakeConfig" : {
"CMAKE_OSX_DEPLOYMENT_TARGET" : "10.11",
"CMAKE_C_COMPILER" : "<path:SULONG_BOOTSTRAP_TOOLCHAIN_NO_HOME>/bin/clang",
"GRAALVM_LLVM_INCLUDE_DIR" : "<path:com.oracle.truffle.llvm.libraries.graalvm.llvm>/include",
},
"license" : "BSD-new",
},
"com.oracle.truffle.llvm.libraries.native" : {
"subDir" : "projects",
"native" : True,
"class" : "CMakeNinjaProject",
# NinjaBuildTask uses only 1 job otherwise
"max_jobs" : "8",
"vpath" : True,
"ninja_targets" : [
"<lib:sulong-native>",
],
"ninja_install_targets" : ["install"],
"results" : [
"bin/<lib:sulong-native>",
],
"buildDependencies" : [
"truffle:TRUFFLE_NFI_NATIVE",
"com.oracle.truffle.llvm.libraries.bitcode",
"sdk:LLVM_TOOLCHAIN",
"NATIVE_MODE_SUPPORT",
],
"buildEnv" : {
"CLANG" : "<path:LLVM_TOOLCHAIN>/bin/clang",
"LIBSULONG" : "<lib:sulong-native>",
"CPPFLAGS" : "-I<path:truffle:TRUFFLE_NFI_NATIVE>/include -I<path:com.oracle.truffle.llvm.libraries.bitcode>/include",
"OS" : "<os>",
"cmakeConfig" : {
"CMAKE_OSX_DEPLOYMENT_TARGET" : "10.11",
"CMAKE_SHARED_LINKER_FLAGS" : "-lm",
"CMAKE_C_COMPILER" : "<path:LLVM_TOOLCHAIN>/bin/clang",
"TRUFFLE_NFI_NATIVE_INCLUDE" : "<path:truffle:TRUFFLE_NFI_NATIVE>/include",
},
"license" : "BSD-new",
},
Expand All @@ -708,20 +737,18 @@
"LIBCXXABI_ENABLE_STATIC" : "NO",
"LIBCXX_INCLUDE_BENCHMARKS": "NO",
"LIBCXX_INCLUDE_TESTS": "NO",
"LIBCXX_CXX_ABI" : "libcxxabi",
# shouldn't this be detected automatically?
"LIBCXX_CXX_ABI_LIBRARY_PATH" : "<path:com.oracle.truffle.llvm.libraries.bitcode.libcxx>/native/lib",
# shouldn't this be detected automatically?
"LIBCXX_CXX_ABI_INCLUDE_PATHS" : "<path:sdk:LLVM_ORG_SRC>/libcxxabi/include",
# using "default" will choose the in-tree version libc++abi and add a build dependency
# from libc++ to libc++abi
"LIBCXX_CXX_ABI" : "default",
"LIBCXX_ENABLE_STATIC" : "NO",
"LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY" : "NO",
"CMAKE_C_COMPILER" : "<toolchainGetToolPath:native,CC>",
"CMAKE_CXX_COMPILER" : "<toolchainGetToolPath:native,CXX>",
"CMAKE_C_COMPILER" : "<path:SULONG_BOOTSTRAP_TOOLCHAIN_NO_HOME>/bin/clang",
"CMAKE_CXX_COMPILER" : "<path:SULONG_BOOTSTRAP_TOOLCHAIN_NO_HOME>/bin/clang++",
"CMAKE_INSTALL_PREFIX" : "native",
},
"buildDependencies" : [
"sdk:LLVM_ORG_SRC",
"SULONG_BOOTSTRAP_TOOLCHAIN",
"SULONG_BOOTSTRAP_TOOLCHAIN_NO_HOME",
"sdk:LLVM_TOOLCHAIN",
"NATIVE_MODE_SUPPORT",
],
Expand Down Expand Up @@ -1488,15 +1515,25 @@
"SULONG_BOOTSTRAP_TOOLCHAIN": {
"native": True,
"relpath": False,
"platformDependent": False,
"platformDependent": True,
"layout": {
"./": "dependency:bootstrap-toolchain-launchers/*",
},
"dependencies": [
"bootstrap-toolchain-launchers",
"buildDependencies" : [
"SULONG_TOOLCHAIN_LAUNCHERS",
],
"distDependencies" : [
"license": "BSD-new",
},

"SULONG_BOOTSTRAP_TOOLCHAIN_NO_HOME": {
"description" : "Bootstrap toolchain without an llvm.home. Use for bootstrapping libraries that should be contained in llvm.home.",
"native": True,
"relpath": False,
"platformDependent": True,
"layout": {
"./": "dependency:bootstrap-toolchain-launchers-no-home/*",
},
"buildDependencies": [
"SULONG_TOOLCHAIN_LAUNCHERS",
],
"license": "BSD-new",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#
# Copyright (c) 2021, Oracle and/or its affiliates.
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to
# endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
#
cmake_minimum_required(VERSION 3.10)
project(com.oracle.truffle.llvm.libraries.bitcode)

set(GRAALVM_LLVM_INCLUDE_DIR)

if(NOT GRAALVM_LLVM_INCLUDE_DIR)
message(FATAL_ERROR "GRAALVM_LLVM_INCLUDE_DIR needs to be set")
endif()

set(LIBCXX_SRC)

if(NOT LIBCXX_SRC)
message(FATAL_ERROR "LIBCXX_SRC needs to be set")
endif()

set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
add_compile_options(-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=${CMAKE_PROJECT_NAME})
add_compile_options(-fdebug-prefix-map=${CMAKE_BINARY_DIR}=${CMAKE_PROJECT_NAME})

if (APPLE)
set(CMAKE_INSTALL_RPATH "@loader_path")
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-undefined,suppress -Wl,-flat_namespace ${CMAKE_SHARED_LINKER_FLAGS}")
else()
set(CMAKE_INSTALL_RPATH "\$ORIGIN")
endif()

if(NOT MX_OS)
message(FATAL_ERROR "MX_OS needs to be set")
endif()

if(NOT MX_ARCH)
message(FATAL_ERROR "MX_ARCH needs to be set")
endif()

add_compile_definitions(OS_${MX_OS} ARCH_${MX_ARCH})

# using glob patterns is not recommended: https://cmake.org/cmake/help/latest/command/file.html#glob
add_library(sulong SHARED
src/abort.c
src/assert.c
src/builtin.c
src/clone.c
src/complex.c
src/crt0.c
src/exec.c
src/exit.c
src/fork.c
src/memcpy.c
src/pthreads.c
src/qsort.c
src/setjmp.c
src/signals.c
src/stat.c
src/string.c
src/sulong_dispose_context.c
)
target_include_directories(sulong PRIVATE ${GRAALVM_LLVM_INCLUDE_DIR})
target_link_options(sulong PRIVATE -nostdlib)
install(TARGETS sulong DESTINATION bin)

add_library(sulong++ SHARED libsulongxx/exception_support.cpp)
target_include_directories(sulong++ PRIVATE ${LIBCXX_SRC}/libcxx/src ${LIBCXX_SRC}/libcxxabi/src)
target_compile_definitions(sulong++ PRIVATE LIBCXXABI_SILENT_TERMINATE)
target_compile_options(sulong++ PRIVATE -std=c++11 -stdlib=libc++ -Wno-undefined-internal)
target_link_options(sulong++ PRIVATE -stdlib=libc++ -Wno-undefined-internal)
install(TARGETS sulong++ DESTINATION bin)
Loading

0 comments on commit 836d28b

Please sign in to comment.