Skip to content

Commit

Permalink
Specify clang and clang++ when building nativeruntime
Browse files Browse the repository at this point in the history
Currently building nativeruntime only works with clang. Using gcc will
result in obscure linker errors related to missing symbols in libstdc++.
While it would be nice to support both, clang is sufficient for now, and
it is fairly easy to obtain on all platforms.

Also add some more error checks for various edge cases.
  • Loading branch information
hoisie committed Nov 10, 2021
1 parent b36f8ae commit 08dbd81
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Expand Up @@ -28,7 +28,6 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up JDK 11.0.8
uses: actions/setup-java@v1
with:
Expand Down
8 changes: 6 additions & 2 deletions nativeruntime/build.gradle
Expand Up @@ -28,6 +28,10 @@ task cmakeNativeRuntime {
doLast {
mkdir "$buildDir/cpp"
exec {
// Building the nativeruntime does not work with GCC due to libstddc++ linker errors.
// TODO: figure out which linker args are needed to build with GCC.
environment "CC", "clang"
environment "CXX", "clang++"
workingDir "$buildDir/cpp"
commandLine 'cmake', "-B", ".", "-S","$projectDir/cpp/"
}
Expand All @@ -36,8 +40,8 @@ task cmakeNativeRuntime {

task configureICU {
onlyIf { !System.getenv('SKIP_ICU_BUILD') }
def os = osName()
doLast {
def os = osName()
if (!file("$projectDir/external/icu/icu4c/source").exists()) {
throw new GradleException("ICU submodule not detected. Please run `git submodule update --init`")
}
Expand All @@ -61,9 +65,9 @@ task configureICU {
task buildICU {
onlyIf { !System.getenv('SKIP_ICU_BUILD') }
dependsOn configureICU
def os = osName()
doLast {
exec {
def os = osName()
if (os.contains("linux") || os.contains("mac")) {
workingDir "$projectDir/external/icu/icu4c/source"
commandLine 'make', '-j4'
Expand Down
19 changes: 12 additions & 7 deletions nativeruntime/cpp/CMakeLists.txt
Expand Up @@ -17,31 +17,36 @@ if(NOT EXISTS "${ANDROID_SQLITE_DIR}/dist/sqlite3.c")
endif()

if(DEFINED ENV{ICU_ROOT_DIR})

if(NOT EXISTS "$ENV{ICU_ROOT_DIR}/lib/libicui18n.a")
message(FATAL_ERROR "ICU_ROOT_DIR does not contain 'lib/libicui18n.a'")
endif()

message(NOTICE "Using $ENV{ICU_ROOT_DIR} as the ICU root dir")
list(APPEND CMAKE_PREFIX_PATH "$ENV{ICU_ROOT_DIR}")
find_library(STATIC_ICUI18N_LIBRARY libicui18n.a)
find_library(STATIC_ICUUC_LIBRARY libicuuc.a)
find_library(STATIC_ICUDATA_LIBRARY libicudata.a)
include_directories($ENV{ICU_ROOT_DIR}/include)
else()
set(ICU_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../external/icu")
set(ICU_SUBMODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../external/icu")

if(NOT EXISTS "${ICU_DIR}/icu4c/source/i18n/ucol.cpp")
if(NOT EXISTS "${ICU_SUBMODULE_DIR}/icu4c/source/i18n/ucol.cpp")
message(FATAL_ERROR "ICU submodule missing. Please run `git submodule update --init`.")
endif()

message(NOTICE "Using ${ICU_DIR} as the ICU root dir")
message(NOTICE "Using ${ICU_SUBMODULE_DIR} as the ICU root dir")

if(NOT EXISTS "${ICU_DIR}/icu4c/source/lib/libicui18n.a")
if(NOT EXISTS "${ICU_SUBMODULE_DIR}/icu4c/source/lib/libicui18n.a")
message(FATAL_ERROR "ICU not built. Please run `./gradlew :nativeruntime:buildICU`.")
endif()

list(APPEND CMAKE_PREFIX_PATH "${ICU_DIR}/icu4c/source/")
list(APPEND CMAKE_PREFIX_PATH "${ICU_SUBMODULE_DIR}/icu4c/source/")
find_library(STATIC_ICUI18N_LIBRARY libicui18n.a)
find_library(STATIC_ICUUC_LIBRARY libicuuc.a)
find_library(STATIC_ICUDATA_LIBRARY libicudata.a)
include_directories(${ICU_DIR}/icu4c/source/i18n)
include_directories(${ICU_DIR}/icu4c/source/common)
include_directories(${ICU_SUBMODULE_DIR}/icu4c/source/i18n)
include_directories(${ICU_SUBMODULE_DIR}/icu4c/source/common)
endif()

# Build flags derived from
Expand Down

0 comments on commit 08dbd81

Please sign in to comment.