Skip to content

Commit 03211da

Browse files
nikarhThomasdezeeuw
authored andcommitted
Added support for vita
1 parent 6a21bba commit 03211da

File tree

7 files changed

+150
-45
lines changed

7 files changed

+150
-45
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ jobs:
6060
strategy:
6161
fail-fast: false
6262
matrix:
63-
# TODO: add the following targets, currently broken.
64-
# "x86_64-unknown-redox"
65-
target: ["aarch64-apple-ios", "aarch64-linux-android", "x86_64-apple-darwin", "x86_64-unknown-fuchsia", "x86_64-pc-windows-msvc", "x86_64-pc-solaris", "x86_64-unknown-illumos", "x86_64-unknown-linux-gnu", "x86_64-unknown-netbsd"]
63+
target: ["aarch64-apple-ios", "aarch64-linux-android", "x86_64-apple-darwin", "x86_64-unknown-fuchsia", "x86_64-pc-windows-msvc", "x86_64-pc-solaris", "x86_64-unknown-illumos", "x86_64-unknown-linux-gnu", "x86_64-unknown-netbsd", "x86_64-unknown-redox"]
6664
steps:
6765
- uses: actions/checkout@master
6866
- name: Install Rust
@@ -72,21 +70,18 @@ jobs:
7270
run: rustup target add ${{ matrix.target }}
7371
- name: Run check
7472
run: cargo hack check --feature-powerset --all-targets --examples --bins --tests --target ${{ matrix.target }}
75-
76-
# Redox needs a nightly compiler for libc:
77-
# https://github.com/rust-lang/libc/issues/2012
78-
Check_Redox:
73+
CheckTier3:
7974
name: Check
8075
runs-on: ubuntu-latest
8176
strategy:
77+
fail-fast: false
8278
matrix:
83-
target: ["x86_64-unknown-redox"]
79+
target: ["armv7-sony-vita-newlibeabihf"]
8480
steps:
85-
- uses: actions/checkout@master
86-
- name: Install Rust nightly
87-
run: rustup update nightly && rustup default nightly
81+
- uses: actions/checkout@v3
82+
- uses: dtolnay/rust-toolchain@nightly
83+
with:
84+
components: "rust-src"
8885
- uses: taiki-e/install-action@cargo-hack
89-
- name: Install Target
90-
run: rustup target add ${{ matrix.target }}
9186
- name: Run check
92-
run: cargo hack check --feature-powerset --all-targets --examples --bins --tests --target ${{ matrix.target }}
87+
run: cargo hack check -Z build-std=std,panic_abort --feature-powerset --all-targets --examples --bins --tests --target ${{ matrix.target }}

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ rustdoc-args = ["--cfg", "docsrs"]
3333
features = ["all"]
3434

3535
[target."cfg(unix)".dependencies]
36-
libc = "0.2.139"
36+
libc = "0.2.149"
3737

3838
[target."cfg(windows)".dependencies]
3939
winapi = { version = "0.3.9", features = ["handleapi", "ws2ipdef", "ws2tcpip"] }

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,15 @@ impl<'a> DerefMut for MaybeUninitSlice<'a> {
331331
/// See [`Socket::set_tcp_keepalive`].
332332
#[derive(Debug, Clone)]
333333
pub struct TcpKeepalive {
334-
#[cfg_attr(target_os = "openbsd", allow(dead_code))]
334+
#[cfg_attr(any(target_os = "openbsd", target_os = "vita"), allow(dead_code))]
335335
time: Option<Duration>,
336336
#[cfg(not(any(
337337
target_os = "openbsd",
338338
target_os = "redox",
339339
target_os = "solaris",
340340
target_os = "nto",
341341
target_os = "espidf",
342+
target_os = "vita",
342343
)))]
343344
interval: Option<Duration>,
344345
#[cfg(not(any(
@@ -348,6 +349,7 @@ pub struct TcpKeepalive {
348349
target_os = "windows",
349350
target_os = "nto",
350351
target_os = "espidf",
352+
target_os = "vita",
351353
)))]
352354
retries: Option<u32>,
353355
}
@@ -363,6 +365,7 @@ impl TcpKeepalive {
363365
target_os = "solaris",
364366
target_os = "nto",
365367
target_os = "espidf",
368+
target_os = "vita",
366369
)))]
367370
interval: None,
368371
#[cfg(not(any(
@@ -372,6 +375,7 @@ impl TcpKeepalive {
372375
target_os = "windows",
373376
target_os = "nto",
374377
target_os = "espidf",
378+
target_os = "vita",
375379
)))]
376380
retries: None,
377381
}

src/sockaddr.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,11 @@ impl From<SocketAddrV4> for SockAddr {
237237
target_os = "openbsd",
238238
target_os = "nto",
239239
target_os = "espidf",
240+
target_os = "vita",
240241
))]
241242
sin_len: 0,
243+
#[cfg(target_os = "vita")]
244+
sin_vport: addr.port().to_be(),
242245
};
243246
let mut storage = MaybeUninit::<sockaddr_storage>::zeroed();
244247
// Safety: A `sockaddr_in` is memory compatible with a `sockaddr_storage`
@@ -278,8 +281,11 @@ impl From<SocketAddrV6> for SockAddr {
278281
target_os = "openbsd",
279282
target_os = "nto",
280283
target_os = "espidf",
284+
target_os = "vita",
281285
))]
282286
sin6_len: 0,
287+
#[cfg(target_os = "vita")]
288+
sin6_vport: addr.port().to_be(),
283289
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
284290
__sin6_src_id: 0,
285291
};

src/socket.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ fn set_common_flags(socket: Socket) -> io::Result<Socket> {
730730
target_os = "netbsd",
731731
target_os = "openbsd",
732732
target_os = "espidf",
733+
target_os = "vita",
733734
))
734735
))]
735736
socket._set_cloexec(true)?;
@@ -1174,6 +1175,7 @@ impl Socket {
11741175
target_os = "solaris",
11751176
target_os = "nto",
11761177
target_os = "espidf",
1178+
target_os = "vita",
11771179
)))]
11781180
pub fn join_multicast_v4_n(
11791181
&self,
@@ -1205,6 +1207,7 @@ impl Socket {
12051207
target_os = "solaris",
12061208
target_os = "nto",
12071209
target_os = "espidf",
1210+
target_os = "vita",
12081211
)))]
12091212
pub fn leave_multicast_v4_n(
12101213
&self,
@@ -1238,6 +1241,7 @@ impl Socket {
12381241
target_os = "fuchsia",
12391242
target_os = "nto",
12401243
target_os = "espidf",
1244+
target_os = "vita",
12411245
)))]
12421246
pub fn join_ssm_v4(
12431247
&self,
@@ -1274,6 +1278,7 @@ impl Socket {
12741278
target_os = "fuchsia",
12751279
target_os = "nto",
12761280
target_os = "espidf",
1281+
target_os = "vita",
12771282
)))]
12781283
pub fn leave_ssm_v4(
12791284
&self,
@@ -1451,6 +1456,7 @@ impl Socket {
14511456
target_os = "windows",
14521457
target_os = "nto",
14531458
target_os = "espidf",
1459+
target_os = "vita",
14541460
)))]
14551461
pub fn set_recv_tos(&self, recv_tos: bool) -> io::Result<()> {
14561462
let recv_tos = if recv_tos { 1 } else { 0 };
@@ -1481,6 +1487,7 @@ impl Socket {
14811487
target_os = "windows",
14821488
target_os = "nto",
14831489
target_os = "espidf",
1490+
target_os = "vita",
14841491
)))]
14851492
pub fn recv_tos(&self) -> io::Result<bool> {
14861493
unsafe {
@@ -1697,14 +1704,24 @@ impl Socket {
16971704
doc,
16981705
all(
16991706
feature = "all",
1700-
not(any(windows, target_os = "haiku", target_os = "openbsd"))
1707+
not(any(
1708+
windows,
1709+
target_os = "haiku",
1710+
target_os = "openbsd",
1711+
target_os = "vita"
1712+
))
17011713
)
17021714
))]
17031715
#[cfg_attr(
17041716
docsrs,
17051717
doc(cfg(all(
17061718
feature = "all",
1707-
not(any(windows, target_os = "haiku", target_os = "openbsd"))
1719+
not(any(
1720+
windows,
1721+
target_os = "haiku",
1722+
target_os = "openbsd",
1723+
target_os = "vita"
1724+
))
17081725
)))
17091726
)]
17101727
pub fn keepalive_time(&self) -> io::Result<Duration> {

src/sys/unix.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ pub(crate) use libc::IP_HDRINCL;
9292
target_os = "haiku",
9393
target_os = "nto",
9494
target_os = "espidf",
95+
target_os = "vita",
9596
)))]
9697
pub(crate) use libc::IP_RECVTOS;
9798
#[cfg(not(any(
@@ -121,6 +122,7 @@ pub(crate) use libc::{
121122
target_os = "fuchsia",
122123
target_os = "nto",
123124
target_os = "espidf",
125+
target_os = "vita",
124126
)))]
125127
pub(crate) use libc::{
126128
ip_mreq_source as IpMreqSource, IP_ADD_SOURCE_MEMBERSHIP, IP_DROP_SOURCE_MEMBERSHIP,
@@ -175,6 +177,7 @@ use libc::TCP_KEEPALIVE as KEEPALIVE_TIME;
175177
target_os = "haiku",
176178
target_os = "openbsd",
177179
target_os = "nto",
180+
target_os = "vita",
178181
)))]
179182
use libc::TCP_KEEPIDLE as KEEPALIVE_TIME;
180183

@@ -237,6 +240,7 @@ type IovLen = usize;
237240
target_os = "nto",
238241
target_vendor = "apple",
239242
target_os = "espidf",
243+
target_os = "vita",
240244
))]
241245
type IovLen = c_int;
242246

@@ -713,6 +717,7 @@ pub(crate) fn try_clone(fd: Socket) -> io::Result<Socket> {
713717
syscall!(fcntl(fd, libc::F_DUPFD_CLOEXEC, 0))
714718
}
715719

720+
#[cfg(not(target_os = "vita"))]
716721
pub(crate) fn set_nonblocking(fd: Socket, nonblocking: bool) -> io::Result<()> {
717722
if nonblocking {
718723
fcntl_add(fd, libc::F_GETFL, libc::F_SETFL, libc::O_NONBLOCK)
@@ -721,6 +726,18 @@ pub(crate) fn set_nonblocking(fd: Socket, nonblocking: bool) -> io::Result<()> {
721726
}
722727
}
723728

729+
#[cfg(target_os = "vita")]
730+
pub(crate) fn set_nonblocking(fd: Socket, nonblocking: bool) -> io::Result<()> {
731+
unsafe {
732+
setsockopt(
733+
fd,
734+
libc::SOL_SOCKET,
735+
libc::SO_NONBLOCK,
736+
nonblocking as libc::c_int,
737+
)
738+
}
739+
}
740+
724741
pub(crate) fn shutdown(fd: Socket, how: Shutdown) -> io::Result<()> {
725742
let how = match how {
726743
Shutdown::Write => libc::SHUT_WR,
@@ -923,7 +940,7 @@ fn into_timeval(duration: Option<Duration>) -> libc::timeval {
923940
}
924941

925942
#[cfg(feature = "all")]
926-
#[cfg(not(any(target_os = "haiku", target_os = "openbsd")))]
943+
#[cfg(not(any(target_os = "haiku", target_os = "openbsd", target_os = "vita")))]
927944
pub(crate) fn keepalive_time(fd: Socket) -> io::Result<Duration> {
928945
unsafe {
929946
getsockopt::<c_int>(fd, IPPROTO_TCP, KEEPALIVE_TIME)
@@ -933,7 +950,12 @@ pub(crate) fn keepalive_time(fd: Socket) -> io::Result<Duration> {
933950

934951
#[allow(unused_variables)]
935952
pub(crate) fn set_tcp_keepalive(fd: Socket, keepalive: &TcpKeepalive) -> io::Result<()> {
936-
#[cfg(not(any(target_os = "haiku", target_os = "openbsd", target_os = "nto")))]
953+
#[cfg(not(any(
954+
target_os = "haiku",
955+
target_os = "openbsd",
956+
target_os = "nto",
957+
target_os = "vita"
958+
)))]
937959
if let Some(time) = keepalive.time {
938960
let secs = into_secs(time);
939961
unsafe { setsockopt(fd, libc::IPPROTO_TCP, KEEPALIVE_TIME, secs)? }
@@ -969,12 +991,18 @@ pub(crate) fn set_tcp_keepalive(fd: Socket, keepalive: &TcpKeepalive) -> io::Res
969991
Ok(())
970992
}
971993

972-
#[cfg(not(any(target_os = "haiku", target_os = "openbsd", target_os = "nto")))]
994+
#[cfg(not(any(
995+
target_os = "haiku",
996+
target_os = "openbsd",
997+
target_os = "nto",
998+
target_os = "vita"
999+
)))]
9731000
fn into_secs(duration: Duration) -> c_int {
9741001
min(duration.as_secs(), c_int::max_value() as u64) as c_int
9751002
}
9761003

9771004
/// Add `flag` to the current set flags of `F_GETFD`.
1005+
#[cfg(not(target_os = "vita"))]
9781006
fn fcntl_add(fd: Socket, get_cmd: c_int, set_cmd: c_int, flag: c_int) -> io::Result<()> {
9791007
let previous = syscall!(fcntl(fd, get_cmd))?;
9801008
let new = previous | flag;
@@ -987,6 +1015,7 @@ fn fcntl_add(fd: Socket, get_cmd: c_int, set_cmd: c_int, flag: c_int) -> io::Res
9871015
}
9881016

9891017
/// Remove `flag` to the current set flags of `F_GETFD`.
1018+
#[cfg(not(target_os = "vita"))]
9901019
fn fcntl_remove(fd: Socket, get_cmd: c_int, set_cmd: c_int, flag: c_int) -> io::Result<()> {
9911020
let previous = syscall!(fcntl(fd, get_cmd))?;
9921021
let new = previous & !flag;
@@ -1066,6 +1095,7 @@ pub(crate) fn from_in6_addr(addr: in6_addr) -> Ipv6Addr {
10661095
target_os = "solaris",
10671096
target_os = "nto",
10681097
target_os = "espidf",
1098+
target_os = "vita",
10691099
)))]
10701100
pub(crate) fn to_mreqn(
10711101
multiaddr: &Ipv4Addr,
@@ -1152,12 +1182,13 @@ impl crate::Socket {
11521182
/// # Notes
11531183
///
11541184
/// On supported platforms you can use [`Type::cloexec`].
1155-
#[cfg(feature = "all")]
1156-
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", unix))))]
1185+
#[cfg(all(feature = "all", not(target_os = "vita")))]
1186+
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", unix, not(target_os = "vita")))))]
11571187
pub fn set_cloexec(&self, close_on_exec: bool) -> io::Result<()> {
11581188
self._set_cloexec(close_on_exec)
11591189
}
11601190

1191+
#[cfg(not(target_os = "vita"))]
11611192
pub(crate) fn _set_cloexec(&self, close_on_exec: bool) -> io::Result<()> {
11621193
if close_on_exec {
11631194
fcntl_add(

0 commit comments

Comments
 (0)