diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 1a6bb4a2eaf34..c8da2815287f7 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -873,6 +873,7 @@ supported_targets! { ("armv7-linux-androideabi", armv7_linux_androideabi), ("thumbv7neon-linux-androideabi", thumbv7neon_linux_androideabi), ("aarch64-linux-android", aarch64_linux_android), + ("riscv64gc-linux-android", riscv64gc_linux_android), ("x86_64-unknown-none-linuxkernel", x86_64_unknown_none_linuxkernel), diff --git a/compiler/rustc_target/src/spec/riscv64gc_linux_android.rs b/compiler/rustc_target/src/spec/riscv64gc_linux_android.rs new file mode 100644 index 0000000000000..3572acd4c3f27 --- /dev/null +++ b/compiler/rustc_target/src/spec/riscv64gc_linux_android.rs @@ -0,0 +1,19 @@ +use crate::spec::{CodeModel, SanitizerSet, Target, TargetOptions}; + +pub fn target() -> Target { + Target { + llvm_target: "riscv64-linux-android".into(), + pointer_width: 64, + data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".into(), + arch: "riscv64".into(), + options: TargetOptions { + code_model: Some(CodeModel::Medium), + cpu: "generic-rv64".into(), + features: "+m,+a,+f,+d,+c".into(), + llvm_abiname: "lp64d".into(), + supported_sanitizers: SanitizerSet::ADDRESS, + max_atomic_width: Some(64), + ..super::android_base::opts() + }, + } +} diff --git a/library/std/src/os/android/raw.rs b/library/std/src/os/android/raw.rs index a255d03208623..5394f6a236175 100644 --- a/library/std/src/os/android/raw.rs +++ b/library/std/src/os/android/raw.rs @@ -155,6 +155,74 @@ mod arch { } } +#[cfg(target_arch = "riscv64")] +mod arch { + use crate::os::raw::{c_uchar, c_ulong}; + use crate::os::unix::raw::{gid_t, uid_t}; + + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type dev_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type mode_t = u32; + + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blkcnt_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blksize_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type ino_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type nlink_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type off_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type time_t = i64; + + #[repr(C)] + #[derive(Clone)] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub struct stat { + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_dev: dev_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad0: [c_uchar; 4], + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __st_ino: ino_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mode: mode_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_nlink: nlink_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_uid: uid_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_gid: gid_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_rdev: dev_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad3: [c_uchar; 4], + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_size: off_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blksize: blksize_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blocks: blkcnt_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime: time_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime_nsec: c_ulong, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime: time_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime_nsec: c_ulong, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime: time_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime_nsec: c_ulong, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ino: ino_t, + } +} + #[cfg(target_arch = "x86_64")] mod arch { use crate::os::raw::{c_long, c_uint, c_ulong}; diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 7a03238f13dff..66225fddd2354 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -157,6 +157,7 @@ target | std | notes `riscv32i-unknown-none-elf` | * | Bare RISC-V (RV32I ISA) `riscv32imac-unknown-none-elf` | * | Bare RISC-V (RV32IMAC ISA) `riscv32imc-unknown-none-elf` | * | Bare RISC-V (RV32IMC ISA) +`riscv64gc-linux-android` | ✓ | 64-bit RISC-V Android `riscv64gc-unknown-none-elf` | * | Bare RISC-V (RV64IMAFDC ISA) `riscv64imac-unknown-none-elf` | * | Bare RISC-V (RV64IMAC ISA) `sparc64-unknown-linux-gnu` | ✓ | SPARC Linux (kernel 4.4, glibc 2.23) diff --git a/src/doc/rustc/src/platform-support/riscv64gc_linux_android.md b/src/doc/rustc/src/platform-support/riscv64gc_linux_android.md new file mode 100644 index 0000000000000..f8be9ef56d612 --- /dev/null +++ b/src/doc/rustc/src/platform-support/riscv64gc_linux_android.md @@ -0,0 +1,52 @@ +# riscv64gc-linux-android + +**Tier: 3** + +Android target similar to "x86_64-linux-android" and "aarch64-linux-android". + +## Target maintainers + +- [@Mao Han](https://github.com/MaoHan001) + +## Requirements + +The requirements for android rust toolchian can be downloaded with: +repo init -u https://android.googlesource.com/platform/manifest -b rust-toolchain + +## Building the target + +The target can be built by enabling it for a `rustc` build. + +```toml +[build] +target = ["riscv64gc-linux-android"] +``` + +Make sure your C compiler is included in `$PATH`, then add it to the `config.toml`: + +```toml +[target.riscv64gc-linux-android] +cc="clang-riscv64-linux-android" +ar="llvm-ar" +``` + +## Building Rust programs + +Rust does not yet ship pre-compiled artifacts for this target. To compile for +this target, you will either need to build Rust with the target enabled (see +"Building the target" above), or build your own copy of `core` by using +`build-std` or similar. + +## Testing +Check adb can list the attached device +$ adb devices +List of devices attached +emulator-5580 device + +Test assembly with stage 3 compiler +$ ./x.py test src/test/assembly --stage 3 --target riscv64gc-linux-android + +## Cross-compilation toolchains and C code + +Compatible C code can be built with Clang's `riscv64-linux-android` targets as long as LLVM based C toolchains are used. +- [clang-riscv64](https://github.com/riscv-android-src/platform-prebuilts-clang-host-linux-x86/tree/riscv64-android-12.0.0_dev)