Last active
April 30, 2017 18:39
-
-
Save joakim-noah/ac35132fd2cd0283c45961312d91e214 to your computer and use it in GitHub Desktop.
LDC for Android/ARM, applied to the release-1.2.x branch 2.072
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 502ec0ff..f120bddc 100644 | |
--- a/runtime/CMakeLists.txt | |
+++ b/runtime/CMakeLists.txt | |
@@ -67,6 +67,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 | |
@@ -495,7 +496,12 @@ include(profile-rt/DefineBuildProfileRT.cmake) | |
# Set up build 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") | |
# This is a bit of a mess as we need to join the two libraries together on | |
# OS X before installing them. After this has run, LIBS_TO_INSTALL contains | |
@@ -661,6 +667,62 @@ macro(build_test_runner name_suffix path_suffix d_flags c_flags) | |
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() | |
endmacro() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment