Created
June 1, 2017 10:10
-
-
Save joakim-noah/d74af3cf1355492557a9c56ef1bf2636 to your computer and use it in GitHub Desktop.
LDC for Android/ARM, applied to the master 1.3 branch 2.073
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt | |
index 32795da6..e02fab7e 100644 | |
--- a/runtime/CMakeLists.txt | |
+++ b/runtime/CMakeLists.txt | |
@@ -29,7 +29,7 @@ else() | |
endif() | |
set(SHARED_LIBS_SUPPORTED OFF) | |
-if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR | |
+if(${CMAKE_SYSTEM_NAME} MATCHES "Rinux" OR | |
${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR | |
APPLE) | |
set(SHARED_LIBS_SUPPORTED ON) | |
@@ -78,6 +78,7 @@ file(GLOB_RECURSE DRUNTIME_D_GCSTUB ${RUNTIME_DIR}/src/gcstub/*.d) | |
list(REMOVE_ITEM DRUNTIME_D ${DRUNTIME_D_GCSTUB}) | |
# remove some modules in rt/ | |
list(REMOVE_ITEM DRUNTIME_D | |
+ ${RUNTIME_DIR}/src/core/stdc/tgmath.d | |
${RUNTIME_DIR}/src/rt/alloca.d | |
${RUNTIME_DIR}/src/rt/deh.d | |
${RUNTIME_DIR}/src/rt/deh_win32.d | |
@@ -551,7 +552,12 @@ include(profile-rt/DefineBuildProfileRT.cmake) | |
# Set up build and install targets | |
# | |
-set(RT_CFLAGS "") | |
+set(CMAKE_C_COMPILER $ENV{NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang) | |
+set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) | |
+set(ANDROID_API "21") | |
+set(RT_CFLAGS "-gcc-toolchain $ENV{NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -fno-integrated-as -target armv7-none-linux-androideabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security -isystem $ENV{NDK}/platforms/android-${ANDROID_API}/arch-arm/usr/include") | |
+set(RT_LDFLAGS "-Wl,-z,nocopyreloc;--sysroot=$ENV{NDK}/platforms/android-${ANDROID_API}/arch-arm;-lgcc;-gcc-toolchain;$ENV{NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64;-target;armv7-none-linux-androideabi;-no-canonical-prefixes;-fuse-ld=bfd;-Wl,--fix-cortex-a8;-Wl,--no-undefined;-Wl,-z,noexecstack;-Wl,-z,relro;-Wl,-z,now;-Wl,--warn-shared-textrel;-Wl,--fatal-warnings;-fPIE;-pie;-lc;-lm") | |
+set(TEST_SO_LDFLAGS "-Wl,-soname,libnative-activity${name_suffix}.so;-shared;--sysroot=$ENV{NDK}/platforms/android-${ANDROID_API}/arch-arm;-lgcc;-gcc-toolchain;$ENV{NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64;-no-canonical-prefixes;-fuse-ld=bfd;-target;armv7-none-linux-androideabi;-Wl,--fix-cortex-a8;-Wl,--no-undefined;-Wl,-z,noexecstack;-Wl,-z,relro;-Wl,-z,now;-Wl,--warn-shared-textrel;-Wl,--fatal-warnings;-llog;-landroid;-lEGL;-lGLESv1_CM;-lc;-lm") | |
if(APPLE AND MULTILIB) | |
# On OS X, build "fat" libraries containing code for both architectures. | |
@@ -689,6 +695,62 @@ function(build_test_runners name_suffix path_suffix is_shared) | |
set_tests_properties(build-phobos2-test-runner${target_suffix} PROPERTIES | |
DEPENDS "build-druntime-ldc-unittest${target_suffix};build-phobos2-ldc-unittest${target_suffix}" | |
) | |
+ | |
+ set(test_runner_o "") | |
+ set(test_runner ${PROJECT_BINARY_DIR}/test-runner${name_suffix}${CMAKE_EXECUTABLE_SUFFIX}) | |
+ set(ANDROID_DIR "${PROJECT_PARENT_DIR}/../android") | |
+ set(test_runner_so ${ANDROID_DIR}/samples/native-activity/libs/armeabi-v7a/libnative-activity${name_suffix}.so) | |
+ set(runner_flags "${flags}") | |
+ if("${flags}" MATCHES "-debug") | |
+ list(APPEND runner_flags -d-debug) | |
+ endif() | |
+ dc("${RUNTIME_DIR}/src/test_runner.d" "${runner_flags}" "${RUNTIME_DIR}" | |
+ "${name_suffix}" test_runner_o druntime_bc) | |
+ add_custom_command( | |
+ OUTPUT ${test_runner} | |
+ COMMAND ${CMAKE_C_COMPILER} ${RT_LDFLAGS} ${test_runner_o} | |
+ ${druntime_o} ${DRUNTIME_C} ${DRUNTIME_ASM} ${phobos2_o} ${PHOBOS2_C} | |
+ -o${test_runner} | |
+ WORKING_DIRECTORY ${PROJECT_PARENT_DIR} | |
+ DEPENDS ${CMAKE_C_COMPILER} | |
+ ${test_runner_o} | |
+ ${druntime_o} | |
+ ${phobos2_o} | |
+ ) | |
+ add_custom_target(test-runner${name_suffix} DEPENDS ${test_runner}) | |
+ set(test_runner_apk_o "") | |
+ dc("${RUNTIME_DIR}/src/test_runner.d" "${runner_flags};-d-version=apk;-I${ANDROID_DIR}" "${RUNTIME_DIR}" | |
+ "-apk${name_suffix}" test_runner_apk_o druntime_bc) | |
+ set(file_apk_o "") | |
+ dc("${PHOBOS2_DIR}/std/file.d" "${flags};-d-version=apk" "${PHOBOS2_DIR}" | |
+ "-apk-unittest${name_suffix}" file_apk_o phobos2_bc) | |
+ set(main_o "") | |
+ dc("${ANDROID_DIR}/samples/native-activity/jni/main.d" "${D_FLAGS};${d_flags};-I${ANDROID_DIR}" "${RUNTIME_DIR}" | |
+ "${name_suffix}" main_o druntime_bc) | |
+ set(sensor_o "") | |
+ dc("${ANDROID_DIR}/android/sensor.d" "${D_FLAGS};${d_flags};-I${ANDROID_DIR}" "${RUNTIME_DIR}" | |
+ "${name_suffix}" sensor_o druntime_bc) | |
+ string(REPLACE " " ";" RT_CFLAGS${name_suffix} ${RT_CFLAGS}) | |
+ set(android_native_app_glue_o "") | |
+ dc("${ANDROID_DIR}/android_native_app_glue.d" "${D_FLAGS};${d_flags};-I${ANDROID_DIR}" "${RUNTIME_DIR}" | |
+ "${name_suffix}" android_native_app_glue_o druntime_bc) | |
+ list(REMOVE_ITEM phobos2_o "${PROJECT_PARENT_DIR}/build/runtime/std/file-unittest${name_suffix}.o") | |
+ add_custom_command( | |
+ OUTPUT ${test_runner_so} | |
+ COMMAND ${CMAKE_C_COMPILER} ${TEST_SO_LDFLAGS} | |
+ ${main_o} ${sensor_o} ${test_runner_apk_o} | |
+ ${file_apk_o} ${android_native_app_glue_o} | |
+ ${druntime_o} ${DRUNTIME_C} ${DRUNTIME_ASM} ${phobos2_o} ${PHOBOS2_C} | |
+ -o${test_runner_so} | |
+ WORKING_DIRECTORY ${PROJECT_PARENT_DIR} | |
+ DEPENDS ${CMAKE_C_COMPILER} | |
+ ${main_o} ${sensor_o} | |
+ ${test_runner_apk_o} ${android_native_app_glue_o} | |
+ ${druntime_o} | |
+ ${phobos2_o} | |
+ ${file_apk_o} | |
+ ) | |
+ add_custom_target(test-runner-apk${name_suffix} DEPENDS ${test_runner_so}) | |
endif() | |
endfunction() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment