-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add risc-v based Android compile target
Signed-off-by: Chen Guoyin <chenguoyin.cgy@linux.alibaba.com> Signed-off-by: Mao Han <han_mao@linux.alibaba.com>
- Loading branch information
Showing
5 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}, | ||
} | ||
} |
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
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
52 changes: 52 additions & 0 deletions
52
src/doc/rustc/src/platform-support/riscv64gc_linux_android.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |