diff --git a/lib/std/core/env.c3 b/lib/std/core/env.c3 index 09b0b61b5..337d1812a 100644 --- a/lib/std/core/env.c3 +++ b/lib/std/core/env.c3 @@ -57,6 +57,7 @@ enum OsType HURD, WASI, EMSCRIPTEN, + ANDROID, } enum ArchType @@ -150,6 +151,7 @@ const bool FREEBSD = LIBC && OS_TYPE == FREEBSD; const bool NETBSD = LIBC && OS_TYPE == NETBSD; const bool BSD_FAMILY = env::FREEBSD || env::OPENBSD || env::NETBSD; const bool WASI = LIBC && OS_TYPE == WASI; +const bool ANDROID = LIBC && OS_TYPE == ANDROID; const bool WASM_NOLIBC @builtin = !LIBC && ARCH_TYPE == ArchType.WASM32 || ARCH_TYPE == ArchType.WASM64; const bool ADDRESS_SANITIZER = $$ADDRESS_SANITIZER; const bool MEMORY_SANITIZER = $$MEMORY_SANITIZER; @@ -182,6 +184,7 @@ macro bool os_is_posix() @const $case SOLARIS: $case TVOS: $case WATCHOS: + $case ANDROID: return true; $case WIN32: $case WASI: diff --git a/lib/std/libc/libc.c3 b/lib/std/libc/libc.c3 index 0cf6af10b..6c0349070 100644 --- a/lib/std/libc/libc.c3 +++ b/lib/std/libc/libc.c3 @@ -203,7 +203,7 @@ const CInt STDIN_FD = 0; const CInt STDOUT_FD = 1; const CInt STDERR_FD = 2; -module libc @if(env::LINUX); +module libc @if(env::LINUX || env::ANDROID); extern CFile __stdin @extern("stdin"); extern CFile __stdout @extern("stdout"); extern CFile __stderr @extern("stderr"); @@ -246,7 +246,7 @@ macro CFile stdin() => __acrt_iob_func(STDIN_FD); macro CFile stdout() => __acrt_iob_func(STDOUT_FD); macro CFile stderr() => __acrt_iob_func(STDERR_FD); -module libc @if(env::LIBC && !env::WIN32 && !env::LINUX && !env::DARWIN && !env::BSD_FAMILY); +module libc @if(env::LIBC && !env::WIN32 && !env::LINUX && !env::ANDROID && !env::DARWIN && !env::BSD_FAMILY); macro CFile stdin() { return (CFile*)(uptr)STDIN_FD; } macro CFile stdout() { return (CFile*)(uptr)STDOUT_FD; } macro CFile stderr() { return (CFile*)(uptr)STDERR_FD; } diff --git a/lib/std/libc/os/android.c3 b/lib/std/libc/os/android.c3 new file mode 100644 index 000000000..54f325c61 --- /dev/null +++ b/lib/std/libc/os/android.c3 @@ -0,0 +1,62 @@ +module libc @if(env::ANDROID); + +// Checked for x86_64, this is notoriously incorrect when comparing with Rust code etc + +def Blksize_t = $typefrom(env::X86_64 ? long.typeid : CInt.typeid); +def Nlink_t = $typefrom(env::X86_64 ? ulong.typeid : CUInt.typeid); +def Blkcnt_t = long; +def Ino_t = ulong; +def Dev_t = ulong; +def Mode_t = uint; +def Ino64_t = ulong; +def Blkcnt64_t = long; + +struct Stat @if(env::X86_64) +{ + Dev_t st_dev; + Ino_t st_ino; + Nlink_t st_nlink; + Mode_t st_mode; + Uid_t st_uid; + Gid_t st_gid; + CInt __pad0; + Dev_t st_rdev; + Off_t st_size; + Blksize_t st_blksize; + Blkcnt_t st_blocks; + Time_t st_atime; + long st_atime_nsec; + Time_t st_mtime; + long st_mtime_nsec; + Time_t st_ctime; + long st_ctime_nsec; + long[3] __unused; +} + +struct Stat @if(!env::X86_64) +{ + Dev_t st_dev; + Ino_t st_ino; + Mode_t st_mode; + Nlink_t st_nlink; + Uid_t st_uid; + Gid_t st_gid; + Dev_t st_rdev; + CInt __pad1; + Off_t st_size; + Blksize_t st_blksize; + CInt __pad2; + Blkcnt_t st_blocks; + Time_t st_atime; + long st_atime_nsec; + Time_t st_mtime; + long st_mtime_nsec; + Time_t st_ctime; + long st_ctime_nsec; + CInt[2] __unused; +} + +extern fn CInt stat(ZString path, Stat* stat); + +extern fn CInt get_nprocs(); +extern fn CInt get_nprocs_conf(); diff --git a/lib/std/libc/os/errno.c3 b/lib/std/libc/os/errno.c3 index 66679fb01..c5db365f9 100644 --- a/lib/std/libc/os/errno.c3 +++ b/lib/std/libc/os/errno.c3 @@ -25,4 +25,4 @@ extern fn void _set_errno(int err) @if(env::WIN32); const ERRNO_DEFAULT @local = !env::LINUX && !env::DARWIN && !env::WIN32; tlocal int _errno_c3 @if(ERRNO_DEFAULT) = 0; fn void errno_set(int err) @if(ERRNO_DEFAULT) => _errno_c3 = err; -fn int errno() @if(ERRNO_DEFAULT) => _errno_c3; \ No newline at end of file +fn int errno() @if(ERRNO_DEFAULT) => _errno_c3; diff --git a/lib/std/time/os/time_posix.c3 b/lib/std/time/os/time_posix.c3 index c8431de31..46b369225 100644 --- a/lib/std/time/os/time_posix.c3 +++ b/lib/std/time/os/time_posix.c3 @@ -67,7 +67,7 @@ const CLOCK_UPTIME_RAW_APPROX = 9; const CLOCK_PROCESS_CPUTIME_ID = 12; const CLOCK_THREAD_CPUTIME_ID = 16; -module std::time::os @if(env::LINUX); +module std::time::os @if(env::LINUX || env::ANDROID); const CLOCK_REALTIME = 0; const CLOCK_MONOTONIC = 1; const CLOCK_PROCESS_CPUTIME_ID = 2; diff --git a/src/build/build.h b/src/build/build.h index 7ff1fb33c..e7994a215 100644 --- a/src/build/build.h +++ b/src/build/build.h @@ -344,6 +344,7 @@ typedef enum { ARCH_OS_TARGET_DEFAULT = -1, ANDROID_AARCH64 = 0, + ANDROID_X86_64, ELF_AARCH64, ELF_RISCV32, ELF_RISCV64, @@ -475,6 +476,11 @@ typedef struct BuildOptions_ const char *crt; const char *crtbegin; } linuxpaths; + struct + { + const char *ndk_path; + int api_version; + } android; int build_threads; const char **libraries_to_fetch; const char **files; @@ -742,6 +748,11 @@ typedef struct const char *crt; const char *crtbegin; } linuxpaths; + struct + { + const char *ndk_path; + int api_version; + } android; } BuildTarget; static const char *x86_cpu_set[8] = { diff --git a/src/build/build_options.c b/src/build/build_options.c index 0bea7e55b..e0e4b4dce 100644 --- a/src/build/build_options.c +++ b/src/build/build_options.c @@ -197,6 +197,9 @@ static void usage(bool full) print_opt("--linux-crt ", "Set the directory to use for finding crt1.o and related files."); print_opt("--linux-crtbegin ", "Set the directory to use for finding crtbegin.o and related files."); PRINTF(""); + print_opt("--android-ndk ", "Set the NDK directory location."); + print_opt("--android-api ", "Set Android API version."); + PRINTF(""); print_opt("--sanitize=