Skip to content

Commit 2e57d64

Browse files
committed
Auto merge of rust-lang#116518 - vita-rust:vita, r=workingjubilee
Updated libc and doc for Vita target Doc changes: - Updated Vita target readme. The recommended approach to build artifacts for the platform now is [cargo-vita](https://crates.io/crates/cargo-vita) which wraps all the convoluted steps previously described in a yaml for `cargo-make` - Updated maintainer list for Vita target. (`@ZetaNumbers` `@pheki` please agree to be added to the list, `@amg98` please let us know if you're still planning on actively maintaining target support) Code changes: - ~Updated libc for rust-lang/libc#3284 and rust-lang/libc#3366~ (Already merged in rust-lang#116527) - In dupfd changed the flag same as for esp target, there is no CLOEXEC on Vita - Enabled `new_pair` since we've implemented `socketpair` in Vita newlib
2 parents 347452e + ba13e37 commit 2e57d64

File tree

4 files changed

+40
-109
lines changed

4 files changed

+40
-109
lines changed

library/std/src/os/fd/owned.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ impl BorrowedFd<'_> {
9797
// We want to atomically duplicate this file descriptor and set the
9898
// CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This
9999
// is a POSIX flag that was added to Linux in 2.6.24.
100-
#[cfg(not(target_os = "espidf"))]
100+
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
101101
let cmd = libc::F_DUPFD_CLOEXEC;
102102

103103
// For ESP-IDF, F_DUPFD is used instead, because the CLOEXEC semantics
104104
// will never be supported, as this is a bare metal framework with
105105
// no capabilities for multi-process execution. While F_DUPFD is also
106106
// not supported yet, it might be (currently it returns ENOSYS).
107-
#[cfg(target_os = "espidf")]
107+
#[cfg(any(target_os = "espidf", target_os = "vita"))]
108108
let cmd = libc::F_DUPFD;
109109

110110
// Avoid using file descriptors below 3 as they are used for stdio
@@ -119,7 +119,7 @@ impl BorrowedFd<'_> {
119119
pub fn try_clone_to_owned(&self) -> crate::io::Result<OwnedFd> {
120120
Err(crate::io::const_io_error!(
121121
crate::io::ErrorKind::Unsupported,
122-
"operation not supported on WASI yet",
122+
"operation not supported on this platform",
123123
))
124124
}
125125
}

library/std/src/sys/unix/net.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl Socket {
103103
}
104104
}
105105

106-
#[cfg(not(any(target_os = "vxworks", target_os = "vita")))]
106+
#[cfg(not(target_os = "vxworks"))]
107107
pub fn new_pair(fam: c_int, ty: c_int) -> io::Result<(Socket, Socket)> {
108108
unsafe {
109109
let mut fds = [0, 0];
@@ -135,7 +135,7 @@ impl Socket {
135135
}
136136
}
137137

138-
#[cfg(any(target_os = "vxworks", target_os = "vita"))]
138+
#[cfg(target_os = "vxworks")]
139139
pub fn new_pair(_fam: c_int, _ty: c_int) -> io::Result<(Socket, Socket)> {
140140
unimplemented!()
141141
}

src/doc/rustc/src/platform-support.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ target | std | host | notes
244244
`armv6-unknown-freebsd` | ✓ | ✓ | ARMv6 FreeBSD
245245
[`armv6-unknown-netbsd-eabihf`](platform-support/netbsd.md) | ✓ | ✓ | ARMv6 NetBSD w/hard-float
246246
[`armv6k-nintendo-3ds`](platform-support/armv6k-nintendo-3ds.md) | ? | | ARMv6K Nintendo 3DS, Horizon (Requires devkitARM toolchain)
247-
[`armv7-sony-vita-newlibeabihf`](platform-support/armv7-sony-vita-newlibeabihf.md) | ? | | ARMv7-A Cortex-A9 Sony PlayStation Vita (requires VITASDK toolchain)
247+
[`armv7-sony-vita-newlibeabihf`](platform-support/armv7-sony-vita-newlibeabihf.md) | | | ARMv7-A Cortex-A9 Sony PlayStation Vita (requires VITASDK toolchain)
248248
[`armv7-unknown-linux-ohos`](platform-support/openharmony.md) | ✓ | | ARMv7-A OpenHarmony |
249249
[`armv7-unknown-linux-uclibceabi`](platform-support/armv7-unknown-linux-uclibceabi.md) | ✓ | ✓ | ARMv7-A Linux with uClibc, softfloat
250250
[`armv7-unknown-linux-uclibceabihf`](platform-support/armv7-unknown-linux-uclibceabihf.md) | ✓ | ? | ARMv7-A Linux with uClibc, hardfloat

src/doc/rustc/src/platform-support/armv7-sony-vita-newlibeabihf.md

+34-103
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
**Tier: 3**
44

5-
This tier supports the ARM Cortex A9 processor running on a PlayStation Vita console. `armv7-vita-newlibeabihf` aims to have support for `std` crate using `newlib` as a bridge.
5+
This tier supports the ARM Cortex A9 processor running on a PlayStation Vita console.
66

77
Rust support for this target is not affiliated with Sony, and is not derived
88
from nor used with any official Sony SDK.
99

1010
## Target maintainers
1111

12-
* [@amg98](https://github.com/amg98)
1312
* [@nikarh](https://github.com/nikarh)
13+
* [@pheki](https://github.com/pheki)
14+
* [@ZetaNumbers](https://github.com/ZetaNumbers)
1415

1516
## Requirements
1617

@@ -20,132 +21,62 @@ This target is cross-compiled, and requires installing [VITASDK](https://vitasdk
2021
`alloc`, and `panic_abort`.
2122

2223
`std` is partially supported, but mostly works. Some APIs are unimplemented
23-
and will simply return an error, such as `std::process`. An allocator is provided
24-
by default.
24+
and will simply return an error, such as `std::process`.
2525

26-
In order to support some APIs, binaries must be linked against `libc` written
27-
for the target, using a linker for the target. These are provided by the
28-
VITASDK toolchain.
26+
This target generates binaries in the ELF format with thumb ISA by default.
27+
28+
Binaries are linked with `arm-vita-eabi-gcc` provided by VITASDK toolchain.
2929

30-
This target generates binaries in the ELF format with thumb ISA.
3130

3231
## Building the target
3332

34-
Rust does not ship pre-compiled artifacts for this target. You can use `build-std` flag to build binaries with `std`:
33+
Rust does not ship pre-compiled artifacts for this target. You can use `build-std` flag to build ELF binaries with `std`:
3534

3635
```sh
3736
cargo build -Z build-std=std,panic_abort --target=armv7-sony-vita-newlibeabihf --release
3837
```
3938

4039
## Building Rust programs
4140

42-
To test your developed rust programs on PlayStation Vita, first you must correctly package your elf. These steps can be preformed using tools available in VITASDK, and can be automated using a tool like `cargo-make`.
41+
The recommended way to build artifacts that can be installed and run on PlayStation Vita is by using the [cargo-vita](https://github.com/vita-rust/cargo-vita) tool. This tool uses `build-std` and VITASDK toolchain to build artifacts runnable on Vita.
42+
43+
To install the tool run:
44+
45+
```sh
46+
cargo install cargo-vita
47+
```
4348

44-
First, set up environment variables for `VITASDK`, and it's binaries:
49+
[VITASDK](https://vitasdk.org/) toolchain must be installed, and the `VITASDK` environment variable must be set to its location, e.g.:
4550

4651
```sh
4752
export VITASDK=/opt/vitasdk
48-
export PATH=$PATH:$VITASDK/bin
4953
```
5054

51-
Use the example below as a template for your project:
55+
Add the following section to your project's `Cargo.toml`:
56+
5257

5358
```toml
54-
[env]
55-
TITLE = "Rust Hello World"
56-
TITLEID = "RUST00001"
57-
58-
# At least a "sce_sys" folder should be place there for app metadata (title, icons, description...)
59-
# You can find sample assets for that on $VITASDK/share/gcc-arm-vita-eabi/samples/hello_world/sce_sys/
60-
STATIC_DIR = "static" # Folder where static assets should be placed (sce_sys folder is at $STATIC_DIR/sce_sys)
61-
CARGO_TARGET_DIR = { script = ["echo ${CARGO_TARGET_DIR:=target}"] }
62-
CARGO_OUT_DIR = "${CARGO_TARGET_DIR}/${RUST_TARGET}/release"
63-
64-
[tasks.build]
65-
description = "Build the project using `cargo`."
66-
command = "cargo"
67-
args = ["build", "-Z", "build-std=std,panic_abort", "--target=armv7-sony-vita-newlibeabihf", "--release"]
68-
69-
[tasks.strip]
70-
description = "Strip the produced ELF executable."
71-
dependencies = ["build"]
72-
command = "arm-vita-eabi-strip"
73-
args = ["-g", '${CARGO_OUT_DIR}/${CARGO_MAKE_CRATE_FS_NAME}.elf']
74-
75-
[tasks.velf]
76-
description = "Build an VELF executable from the obtained ELF file."
77-
dependencies = ["strip"]
78-
command = "vita-elf-create"
79-
args = ['${CARGO_OUT_DIR}/${CARGO_MAKE_CRATE_NAME}.elf', '${CARGO_OUT_DIR}/${CARGO_MAKE_CRATE_NAME}.velf']
80-
81-
[tasks.eboot-bin]
82-
description = "Build an `eboot.bin` file from the obtained VELF file."
83-
dependencies = ["velf"]
84-
command = "vita-make-fself"
85-
args = ["-s", '${CARGO_OUT_DIR}/${CARGO_MAKE_CRATE_NAME}.velf', '${CARGO_OUT_DIR}/eboot.bin']
86-
87-
[tasks.param-sfo]
88-
description = "Build the `param.sfo` manifest using with given TITLE and TITLEID."
89-
command = "vita-mksfoex"
90-
args = ["-s", 'TITLE_ID=${TITLEID}', '${TITLE}', '${CARGO_OUT_DIR}/param.sfo']
91-
92-
[tasks.manifest]
93-
description = "List all static resources into a manifest file."
94-
script = [
95-
'mkdir -p "${CARGO_OUT_DIR}"',
96-
'''
97-
if [ -d "${STATIC_DIR}" ]; then
98-
find "${STATIC_DIR}" -type f > "${CARGO_OUT_DIR}/MANIFEST"
99-
else
100-
touch "${CARGO_OUT_DIR}/MANIFEST"
101-
fi
102-
'''
103-
]
104-
105-
[tasks.vpk]
106-
description = "Build a VPK distribution of the project executable and resources."
107-
dependencies = ["eboot-bin", "param-sfo", "manifest"]
108-
script_runner = "@rust"
109-
script = [
110-
'''
111-
use std::io::BufRead;
112-
use std::fs::File;
113-
114-
fn main() {
115-
116-
let crate_name = env!("CARGO_MAKE_CRATE_NAME");
117-
let static_dir = env!("STATIC_DIR");
118-
let out_dir = std::path::PathBuf::from(env!("CARGO_OUT_DIR"));
119-
120-
let mut cmd = ::std::process::Command::new("vita-pack-vpk");
121-
cmd.arg("-s").arg(out_dir.join("param.sfo"));
122-
cmd.arg("-b").arg(out_dir.join("eboot.bin"));
123-
124-
// Add files from MANIFEST
125-
if let Ok(file) = File::open(out_dir.join("MANIFEST")) {
126-
let mut reader = ::std::io::BufReader::new(file);
127-
let mut lines = reader.lines();
128-
while let Some(Ok(line)) = lines.next() {
129-
let p1 = ::std::path::PathBuf::from(line); // path on FS
130-
let p2 = p1.strip_prefix(static_dir).unwrap(); // path in VPK
131-
cmd.arg("--add").arg(format!("{}={}", p1.display(), p2.display()));
132-
}
133-
}
134-
135-
cmd.arg(out_dir.join(format!("{}.vpk", crate_name)))
136-
.output()
137-
.expect("command failed.");
138-
}
139-
'''
140-
]
59+
[package.metadata.vita]
60+
# A unique 9 character alphanumeric identifier of the app.
61+
title_id = "RUSTAPP01"
62+
# A title that will be used for the app. Optional, name will be used if not defined
63+
title_name = "My application"
14164
```
14265

143-
After running the above script, you should be able to get a *.vpk file in the same folder your *.elf executable resides. Now you can pick it and install it on your own PlayStation Vita using, or you can use an [Vita3K](https://vita3k.org/) emulator.
66+
To build a VPK with ELF in the release profile, run:
67+
68+
```sh
69+
cargo vita build vpk --release
70+
```
71+
72+
After building a *.vpk file it can be uploaded to a PlayStation Vita and installed, or used with a [Vita3K](https://vita3k.org/) emulator.
14473

14574
## Testing
14675

147-
Currently there is no support to run the rustc test suite for this target.
76+
The default Rust test runner is supported, and tests can be compiled to an elf and packed to a *.vpk file using `cargo-vita` tool. Filtering tests is not currently supported since passing command-line arguments to the executable is not supported on Vita, so the runner will always execute all tests.
77+
78+
The Rust test suite for `library/std` is not yet supported.
14879

14980
## Cross-compilation
15081

151-
This target can be cross-compiled from `x86_64` on either Windows, MacOS or Linux systems. Other hosts are not supported for cross-compilation.
82+
This target can be cross-compiled from `x86_64` on Windows, MacOS or Linux systems. Other hosts are not supported for cross-compilation.

0 commit comments

Comments
 (0)