Skip to content

Commit

Permalink
Rollup merge of #72133 - bdbai:master, r=joshtriplett
Browse files Browse the repository at this point in the history
Add target thumbv7a-uwp-windows-msvc

Add target spec for thumbv7a-uwp-windows-msvc, so that libraries written in Rust will have a chance to run on ARM-based devices with Windows 10.

So far I managed to create a proof-of-concept library for Universal Windows Platform apps to consume and it worked on a Windows Phone. However, building a standalone executable seemed troublesome due to `LLVM ERROR: target does not implement codeview register mapping` stuff (see also #52659 (comment) ).

Steps to test:
1. Clone and build this version
```sh
git clone https://github.com/bdbai/rust.git
cd rust
python x.py build -i --target thumbv7a-uwp-windows-msvc --stage 1 src/libstd
rustup toolchain link arm-uwp-stage1 .\build\x86_64-pc-windows-msvc\stage1\
```
2. Create a new library crate
```sh
cargo new --lib arm-uwp-test
cd arm-uwp-test
```
3. Change `crate-type` in `Cargo.toml` to `staticlib`
```toml
[lib]
crate-type=["staticlib"]
```
4. Replace the following code in `src/lib.rs`
```rust
#[no_mangle]
pub extern "system" fn call_rust() -> i32 {
    2333
}
```
5. Build the crate
```sh
cargo +arm-uwp-stage1 build -v --target thumbv7a-uwp-windows-msvc
```
6. `arm-uwp-test.lib` should appear in `target\thumbv7a-uwp-windows-msvc\debug`

To consume this library:
1. Make sure Visual Studio 2017 and Windows 10 SDK (10.0.17134 or above) are installed
2. Create a new Blank App (C++/WinRT) in Visual Studio 2017 (Visual Studio 2019 cannot deploy UWP apps to Windows Phone)
3. Go to Property Pages, and then Linker->Input->Additional Dependencies, add `arm-uwp-test.lib` produced just now
4. Manually declare function prototypes in `MainPage.h`
```c++
extern "C" {
    int call_rust();
}
```
5. Replace the `ClickHandler` part in `MainPage.cpp`
```c++
myButton().Content(box_value(std::to_wstring(call_rust())));
```
6. Build and deploy this app to an ARM device running Windows 10. The app should run and show `2333` when the button is clicked.
  • Loading branch information
RalfJung committed May 22, 2020
2 parents ee0c7d4 + 5bfb7e7 commit 715f1e8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> Command {
"x86_64" => Some("x64".to_string()),
"x86" => Some("x86".to_string()),
"aarch64" => Some("arm64".to_string()),
"arm" => Some("arm".to_string()),
_ => None,
};
if let Some(ref a) = arch {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ supported_targets! {
("i686-uwp-windows-msvc", i686_uwp_windows_msvc),
("i586-pc-windows-msvc", i586_pc_windows_msvc),
("thumbv7a-pc-windows-msvc", thumbv7a_pc_windows_msvc),
("thumbv7a-uwp-windows-msvc", thumbv7a_uwp_windows_msvc),

("asmjs-unknown-emscripten", asmjs_unknown_emscripten),
("wasm32-unknown-emscripten", wasm32_unknown_emscripten),
Expand Down
30 changes: 30 additions & 0 deletions src/librustc_target/spec/thumbv7a_uwp_windows_msvc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crate::spec::{LinkerFlavor, PanicStrategy, Target, TargetOptions, TargetResult};

pub fn target() -> TargetResult {
let mut base = super::windows_uwp_msvc_base::opts();
base.max_atomic_width = Some(64);
base.has_elf_tls = true;

// FIXME(jordanrh): use PanicStrategy::Unwind when SEH is
// implemented for windows/arm in LLVM
base.panic_strategy = PanicStrategy::Abort;

Ok(Target {
llvm_target: "thumbv7a-pc-windows-msvc".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
target_c_int_width: "32".to_string(),
data_layout: "e-m:w-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
arch: "arm".to_string(),
target_os: "windows".to_string(),
target_env: "msvc".to_string(),
target_vendor: "uwp".to_string(),
linker_flavor: LinkerFlavor::Msvc,
options: TargetOptions {
features: "+vfp3,+neon".to_string(),
cpu: "generic".to_string(),
abi_blacklist: super::arm_base::abi_blacklist(),
..base
},
})
}

0 comments on commit 715f1e8

Please sign in to comment.