Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 18 additions & 1 deletion clib/gc_chooser.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ enum gc_option { gc_opt_large, gc_opt_malloc, gc_opt_boehm } gc_option;
#include <gc.h>
#endif

#if defined(WITH_LIBGC) && defined(__APPLE__)
#include <TargetConditionals.h>
#if TARGET_OS_IPHONE
static int GC_CALLBACK nit_ios_has_static_roots(const char *dlpi_name,
void *section_start, size_t section_size) {
if (dlpi_name == NULL) return 1; /* unknown origin: keep it to be safe */
return strstr(dlpi_name, ".app/") != NULL;
}
#endif
#endif

void *nit_raw_alloc(size_t s0)
{
switch (gc_option) {
Expand Down Expand Up @@ -116,7 +127,13 @@ void initialize_gc_option(void) {
/* Initialize GC (if needed) */
switch(gc_option) {
#ifdef WITH_LIBGC
case gc_opt_boehm: GC_INIT(); break;
case gc_opt_boehm:
#if defined(__APPLE__) && TARGET_OS_IPHONE
/* Must be set before GC_INIT(), which registers the dyld roots. */
GC_register_has_static_roots_callback(nit_ios_has_static_roots);
#endif
GC_INIT();
break;
#endif
default: break; /* Nothing */
}
Expand Down
7 changes: 6 additions & 1 deletion lib/android/platform.nit
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
# limitations under the License.

# Triggers compilation for the android platform
module platform is platform "android"
module platform is
platform "android"

# Require Android 6.0 for bdwgc which has known issues before API 23
android_api_min 23
end

import java
import app
Expand Down
1 change: 1 addition & 0 deletions misc/docker/full/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ RUN dpkg --add-architecture i386 \
&& rm -rf /var/lib/apt/lists/*

# Install android SDK and NDK.
# Note: keep the NDK version in sync with the compiler's ndk_version string.
RUN mkdir -p /opt \
&& cd /opt \
&& curl -fL https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -o cmdline-tools.zip \
Expand Down
21 changes: 10 additions & 11 deletions src/platform/android.nit
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class AndroidToolchain
var app_version = project.version

var app_min_api = project.min_api
if app_min_api == null then app_min_api = 10
if app_min_api == null then app_min_api = 23

var app_target_api = project.target_api
if app_target_api == null then app_target_api = app_min_api
Expand Down Expand Up @@ -152,6 +152,9 @@ class AndroidToolchain
# TODO make configurable client-side
var compile_sdk_version = app_target_api

# Prefer the NDK version installed by `misc/docker/full/Dockerfile`.
var ndk_version = "25.2.9519653"

var local_build_gradle = """
apply plugin: 'com.android.application'

Expand All @@ -160,6 +163,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion {{{compile_sdk_version}}}
buildToolsVersion "{{{build_tools_version}}}"
ndkVersion "{{{ndk_version}}}"

defaultConfig {
applicationId "{{{app_package}}}"
Expand All @@ -171,11 +175,6 @@ android {
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
externalNativeBuild {
cmake {
arguments "-DANDROID_TOOLCHAIN=gcc"
}
}
}

buildTypes {
Expand Down Expand Up @@ -212,17 +211,17 @@ dependencies {
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.android.tools.build:gradle:7.4.2'
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
"""
Expand Down Expand Up @@ -299,7 +298,7 @@ set(lib_build_DIR ../libgc/outputs)
file(MAKE_DIRECTORY ${lib_build_DIR})

## Config
add_definitions("-DALL_INTERIOR_POINTERS -DGC_THREADS -DUSE_MMAP -DUSE_MUNMAP -DJAVA_FINALIZATION -DNO_EXECUTE_PERMISSION -DGC_DONT_REGISTER_MAIN_STATIC_DATA")
add_definitions("-DALL_INTERIOR_POINTERS -DGC_THREADS -DUSE_MMAP -DUSE_MUNMAP -DJAVA_FINALIZATION -DNO_EXECUTE_PERMISSION -DGC_DONT_REGISTER_MAIN_STATIC_DATA -DGC_BUILTIN_ATOMIC")
set(enable_threads TRUE)
set(CMAKE_USE_PTHREADS_INIT TRUE)

Expand Down Expand Up @@ -329,7 +328,7 @@ target_include_directories(nit_app PRIVATE ${ANDROID_NDK}/sources/android/native

# Link!

target_link_libraries(nit_app gc-lib
target_link_libraries(nit_app gc
{{{target_link_libraries.join("\n\t")}}})
"""
cmakelists.write_to_file "{android_app_main}/cpp/CMakeLists.txt"
Expand Down
10 changes: 3 additions & 7 deletions src/platform/app_annotations.nit
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@ class AppProject
var version = "0.1"

# Numerical version code of the application
var version_code: Int is lazy do

# Get the date and time (down to the minute) as string
var gmtime = new Tm.gmtime
var local_time_s = gmtime.strftime("%y%m%d%H%M")
return local_time_s.to_i
end
#
# Needs to fit within the 32 bits expected by Android.
var version_code: Int is lazy do return get_time / 60

# Extra folders where to find platform specific resource files
var files = new Array[String]
Expand Down
6 changes: 3 additions & 3 deletions src/platform/ios.nit
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private class IOSToolchain
if not dir.file_exists then dir.mkdir

# Create a PBX project file
var pbx = new PbxprojectTemplate(project_name)
var pbx = new PbxprojectTemplate(project_name, app_project.namespace)

## Register all source files
for file in cfiles do pbx.add_file new PbxFile(file)
Expand All @@ -172,8 +172,8 @@ private class IOSToolchain
var bdwgc_dir = bdwgc_dir
assert bdwgc_dir != null

pbx.cflags = "-I '{bdwgc_dir}/include/' -I '{bdwgc_dir}/libatomic_ops/src' -fno-strict-aliasing " +
"-DWITH_LIBGC -DNO_EXECUTE_PERMISSION -DALL_INTERIOR_POINTERS -DGC_NO_THREADS_DISCOVERY -DNO_DYLD_BIND_FULLY_IMAGE " +
pbx.cflags = "-I {bdwgc_dir}/include/ -fno-strict-aliasing " +
"-DGC_BUILTIN_ATOMIC -DWITH_LIBGC -DNO_EXECUTE_PERMISSION -DALL_INTERIOR_POINTERS -DGC_NO_THREADS_DISCOVERY -DNO_DYLD_BIND_FULLY_IMAGE " +
"-DGC_DISABLE_INCREMENTAL -DGC_THREADS -DUSE_MMAP -DUSE_MUNMAP -DGC_GCJ_SUPPORT -DJAVA_FINALIZATION "

var gc_file = new PbxFile("{bdwgc_dir}/extra/gc.c")
Expand Down
9 changes: 7 additions & 2 deletions src/platform/xcode_templates.nit
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ class PbxprojectTemplate
# Name of the project
var name: String

# PRODUCT_BUNDLE_IDENTIFIER, must match `CFBundleIdentifier` of the `Info.plist`
var bundle_identifier: String

# OTHER_CFLAGS
var cflags = "" is writable

Expand Down Expand Up @@ -391,7 +394,7 @@ class PbxprojectTemplate
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -417,7 +420,7 @@ class PbxprojectTemplate
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -432,6 +435,7 @@ class PbxprojectTemplate
INFOPLIST_FILE = {{{name}}}/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_CFLAGS = "{{{cflags.escape_to_c}}}";
PRODUCT_BUNDLE_IDENTIFIER = "{{{bundle_identifier}}}";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand All @@ -443,6 +447,7 @@ class PbxprojectTemplate
INFOPLIST_FILE = {{{name}}}/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_CFLAGS = "{{{cflags.escape_to_c}}}";
PRODUCT_BUNDLE_IDENTIFIER = "{{{bundle_identifier}}}";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand Down
2 changes: 1 addition & 1 deletion tests/sav/niti/test_platform_android.res
Original file line number Diff line number Diff line change
@@ -1 +1 @@
../lib/android/platform.nit:18,20--37: Error: target platform `android` unknown.
../lib/android/platform.nit:19,2--19: Error: target platform `android` unknown.
Loading