fix: android build (#30360)
Some checks are pending
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / build libs (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions

Fix build error on Android.

Patches from https://github.com/cions/termux-deno
This commit is contained in:
cions 2025-08-12 22:47:18 +09:00 committed by GitHub
parent c69a8fa414
commit ebfd3c3d7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 248 additions and 66 deletions

View file

@ -195,7 +195,7 @@ deno_subprocess_windows.workspace = true
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
nix.workspace = true nix.workspace = true
shell-escape = "=0.1.5" shell-escape = "=0.1.5"
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies] [target.'cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))'.dependencies]
tokio-vsock.workspace = true tokio-vsock.workspace = true
[dev-dependencies] [dev-dependencies]

View file

@ -732,9 +732,17 @@ fn wait_for_start(
use tokio::io::BufReader; use tokio::io::BufReader;
use tokio::net::TcpListener; use tokio::net::TcpListener;
use tokio::net::UnixSocket; use tokio::net::UnixSocket;
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
use tokio_vsock::VsockAddr; use tokio_vsock::VsockAddr;
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
use tokio_vsock::VsockListener; use tokio_vsock::VsockListener;
init_v8(&Flags::default()); init_v8(&Flags::default());
@ -774,7 +782,11 @@ fn wait_for_start(
let (rx, tx) = stream.into_split(); let (rx, tx) = stream.into_split();
(Box::new(rx), Box::new(tx)) (Box::new(rx), Box::new(tx))
} }
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
Some(("vsock", addr)) => { Some(("vsock", addr)) => {
let Some((cid, port)) = addr.split_once(':') else { let Some((cid, port)) = addr.split_once(':') else {
deno_core::anyhow::bail!("invalid vsock addr"); deno_core::anyhow::bail!("invalid vsock addr");

View file

@ -46,7 +46,7 @@ tower.workspace = true
tower-http.workspace = true tower-http.workspace = true
tower-service.workspace = true tower-service.workspace = true
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies] [target.'cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))'.dependencies]
tokio-vsock.workspace = true tokio-vsock.workspace = true
[dev-dependencies] [dev-dependencies]

View file

@ -1121,12 +1121,20 @@ pub fn create_http_client(
Proxy::Unix { .. } => { Proxy::Unix { .. } => {
return Err(HttpClientCreateError::UnixProxyNotSupportedOnWindows); return Err(HttpClientCreateError::UnixProxyNotSupportedOnWindows);
} }
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
Proxy::Vsock { cid, port } => { Proxy::Vsock { cid, port } => {
let target = proxy::Target::new_vsock(cid, port); let target = proxy::Target::new_vsock(cid, port);
proxy::Intercept::all(target) proxy::Intercept::all(target)
} }
#[cfg(not(any(target_os = "linux", target_os = "macos")))] #[cfg(not(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
)))]
Proxy::Vsock { .. } => { Proxy::Vsock { .. } => {
return Err(HttpClientCreateError::VsockProxyNotSupported); return Err(HttpClientCreateError::VsockProxyNotSupported);
} }

View file

@ -31,7 +31,11 @@ use tokio::net::UnixStream;
use tokio_rustls::TlsConnector; use tokio_rustls::TlsConnector;
use tokio_rustls::client::TlsStream; use tokio_rustls::client::TlsStream;
use tokio_socks::tcp::Socks5Stream; use tokio_socks::tcp::Socks5Stream;
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
use tokio_vsock::VsockStream; use tokio_vsock::VsockStream;
use tower_service::Service; use tower_service::Service;
@ -77,7 +81,7 @@ pub(crate) enum Target {
Unix { Unix {
path: PathBuf, path: PathBuf,
}, },
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
Vsock { Vsock {
cid: u32, cid: u32,
port: u32, port: u32,
@ -185,7 +189,11 @@ impl Intercept {
Target::Unix { .. } => { Target::Unix { .. } => {
// Auth not supported for Unix sockets // Auth not supported for Unix sockets
} }
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
Target::Vsock { .. } => { Target::Vsock { .. } => {
// Auth not supported for Vsock sockets // Auth not supported for Vsock sockets
} }
@ -272,7 +280,7 @@ impl Target {
Target::Unix { path } Target::Unix { path }
} }
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
pub(crate) fn new_vsock(cid: u32, port: u32) -> Self { pub(crate) fn new_vsock(cid: u32, port: u32) -> Self {
Target::Vsock { cid, port } Target::Vsock { cid, port }
} }
@ -481,7 +489,7 @@ pub enum Proxied<T> {
#[cfg(not(windows))] #[cfg(not(windows))]
Unix(TokioIo<UnixStream>), Unix(TokioIo<UnixStream>),
/// Forwarded via Vsock socket /// Forwarded via Vsock socket
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
Vsock(TokioIo<VsockStream>), Vsock(TokioIo<VsockStream>),
} }
@ -587,7 +595,11 @@ where
Ok(Proxied::Unix(TokioIo::new(io))) Ok(Proxied::Unix(TokioIo::new(io)))
}) })
} }
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
Target::Vsock { cid, port } => Box::pin(async move { Target::Vsock { cid, port } => Box::pin(async move {
let addr = tokio_vsock::VsockAddr::new(cid, port); let addr = tokio_vsock::VsockAddr::new(cid, port);
let io = VsockStream::connect(addr).await?; let io = VsockStream::connect(addr).await?;
@ -704,7 +716,11 @@ where
Proxied::SocksTls(ref mut p) => Pin::new(p).poll_read(cx, buf), Proxied::SocksTls(ref mut p) => Pin::new(p).poll_read(cx, buf),
#[cfg(not(windows))] #[cfg(not(windows))]
Proxied::Unix(ref mut p) => Pin::new(p).poll_read(cx, buf), Proxied::Unix(ref mut p) => Pin::new(p).poll_read(cx, buf),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
Proxied::Vsock(ref mut p) => Pin::new(p).poll_read(cx, buf), Proxied::Vsock(ref mut p) => Pin::new(p).poll_read(cx, buf),
} }
} }
@ -727,7 +743,11 @@ where
Proxied::SocksTls(ref mut p) => Pin::new(p).poll_write(cx, buf), Proxied::SocksTls(ref mut p) => Pin::new(p).poll_write(cx, buf),
#[cfg(not(windows))] #[cfg(not(windows))]
Proxied::Unix(ref mut p) => Pin::new(p).poll_write(cx, buf), Proxied::Unix(ref mut p) => Pin::new(p).poll_write(cx, buf),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
Proxied::Vsock(ref mut p) => Pin::new(p).poll_write(cx, buf), Proxied::Vsock(ref mut p) => Pin::new(p).poll_write(cx, buf),
} }
} }
@ -744,7 +764,11 @@ where
Proxied::SocksTls(ref mut p) => Pin::new(p).poll_flush(cx), Proxied::SocksTls(ref mut p) => Pin::new(p).poll_flush(cx),
#[cfg(not(windows))] #[cfg(not(windows))]
Proxied::Unix(ref mut p) => Pin::new(p).poll_flush(cx), Proxied::Unix(ref mut p) => Pin::new(p).poll_flush(cx),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
Proxied::Vsock(ref mut p) => Pin::new(p).poll_flush(cx), Proxied::Vsock(ref mut p) => Pin::new(p).poll_flush(cx),
} }
} }
@ -761,7 +785,11 @@ where
Proxied::SocksTls(ref mut p) => Pin::new(p).poll_shutdown(cx), Proxied::SocksTls(ref mut p) => Pin::new(p).poll_shutdown(cx),
#[cfg(not(windows))] #[cfg(not(windows))]
Proxied::Unix(ref mut p) => Pin::new(p).poll_shutdown(cx), Proxied::Unix(ref mut p) => Pin::new(p).poll_shutdown(cx),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
Proxied::Vsock(ref mut p) => Pin::new(p).poll_shutdown(cx), Proxied::Vsock(ref mut p) => Pin::new(p).poll_shutdown(cx),
} }
} }
@ -775,7 +803,11 @@ where
Proxied::SocksTls(ref p) => p.is_write_vectored(), Proxied::SocksTls(ref p) => p.is_write_vectored(),
#[cfg(not(windows))] #[cfg(not(windows))]
Proxied::Unix(ref p) => p.is_write_vectored(), Proxied::Unix(ref p) => p.is_write_vectored(),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
Proxied::Vsock(ref p) => p.is_write_vectored(), Proxied::Vsock(ref p) => p.is_write_vectored(),
} }
} }
@ -799,7 +831,11 @@ where
Proxied::SocksTls(ref mut p) => Pin::new(p).poll_write_vectored(cx, bufs), Proxied::SocksTls(ref mut p) => Pin::new(p).poll_write_vectored(cx, bufs),
#[cfg(not(windows))] #[cfg(not(windows))]
Proxied::Unix(ref mut p) => Pin::new(p).poll_write_vectored(cx, bufs), Proxied::Unix(ref mut p) => Pin::new(p).poll_write_vectored(cx, bufs),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
Proxied::Vsock(ref mut p) => Pin::new(p).poll_write_vectored(cx, bufs), Proxied::Vsock(ref mut p) => Pin::new(p).poll_write_vectored(cx, bufs),
} }
} }
@ -832,7 +868,11 @@ where
} }
#[cfg(not(windows))] #[cfg(not(windows))]
Proxied::Unix(_) => Connected::new(), Proxied::Unix(_) => Connected::new(),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
Proxied::Vsock(_) => Connected::new(), Proxied::Vsock(_) => Connected::new(),
} }
} }

View file

@ -57,7 +57,7 @@ thiserror.workspace = true
tokio.workspace = true tokio.workspace = true
tokio-util = { workspace = true, features = ["io"] } tokio-util = { workspace = true, features = ["io"] }
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies] [target.'cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))'.dependencies]
tokio-vsock.workspace = true tokio-vsock.workspace = true
[dev-dependencies] [dev-dependencies]

View file

@ -1056,7 +1056,11 @@ where
NetworkStream::Unix(conn) => { NetworkStream::Unix(conn) => {
serve_http(conn, connection_properties, lifetime, tx, options) serve_http(conn, connection_properties, lifetime, tx, options)
} }
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
NetworkStream::Vsock(conn) => { NetworkStream::Vsock(conn) => {
serve_http(conn, connection_properties, lifetime, tx, options) serve_http(conn, connection_properties, lifetime, tx, options)
} }

View file

@ -1686,7 +1686,7 @@ fn extract_network_stream<U: CanDowncastUpgrade>(
Ok(res) => return res, Ok(res) => return res,
Err(x) => x, Err(x) => x,
}; };
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
let upgraded = let upgraded =
match maybe_extract_network_stream::<tokio_vsock::VsockStream, _>(upgraded) match maybe_extract_network_stream::<tokio_vsock::VsockStream, _>(upgraded)
{ {

View file

@ -165,7 +165,11 @@ impl HttpPropertyExtractor for DefaultHttpPropertyExtractor {
NetworkStreamAddress::Ip(ip) => Some(ip.port() as _), NetworkStreamAddress::Ip(ip) => Some(ip.port() as _),
#[cfg(unix)] #[cfg(unix)]
NetworkStreamAddress::Unix(_) => None, NetworkStreamAddress::Unix(_) => None,
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
NetworkStreamAddress::Vsock(vsock) => Some(vsock.port()), NetworkStreamAddress::Vsock(vsock) => Some(vsock.port()),
NetworkStreamAddress::Tunnel(ref addr) => Some(addr.port() as _), NetworkStreamAddress::Tunnel(ref addr) => Some(addr.port() as _),
}; };
@ -173,7 +177,11 @@ impl HttpPropertyExtractor for DefaultHttpPropertyExtractor {
NetworkStreamAddress::Ip(addr) => Rc::from(addr.ip().to_string()), NetworkStreamAddress::Ip(addr) => Rc::from(addr.ip().to_string()),
#[cfg(unix)] #[cfg(unix)]
NetworkStreamAddress::Unix(_) => Rc::from("unix"), NetworkStreamAddress::Unix(_) => Rc::from("unix"),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
NetworkStreamAddress::Vsock(addr) => { NetworkStreamAddress::Vsock(addr) => {
Rc::from(format!("vsock:{}", addr.cid())) Rc::from(format!("vsock:{}", addr.cid()))
} }
@ -216,7 +224,11 @@ fn listener_properties(
NetworkStreamAddress::Ip(ip) => Some(ip.port() as _), NetworkStreamAddress::Ip(ip) => Some(ip.port() as _),
#[cfg(unix)] #[cfg(unix)]
NetworkStreamAddress::Unix(_) => None, NetworkStreamAddress::Unix(_) => None,
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
NetworkStreamAddress::Vsock(vsock) => Some(vsock.port()), NetworkStreamAddress::Vsock(vsock) => Some(vsock.port()),
NetworkStreamAddress::Tunnel(addr) => Some(addr.port() as _), NetworkStreamAddress::Tunnel(addr) => Some(addr.port() as _),
}; };
@ -263,7 +275,11 @@ fn req_host_from_addr(
percent_encoding::NON_ALPHANUMERIC, percent_encoding::NON_ALPHANUMERIC,
) )
.to_string(), .to_string(),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
NetworkStreamAddress::Vsock(vsock) => { NetworkStreamAddress::Vsock(vsock) => {
format!("{}:{}", vsock.cid(), vsock.port()) format!("{}:{}", vsock.cid(), vsock.port())
} }
@ -283,7 +299,11 @@ fn req_scheme_from_stream_type(stream_type: NetworkStreamType) -> &'static str {
NetworkStreamType::Tls | NetworkStreamType::Tunnel => "https://", NetworkStreamType::Tls | NetworkStreamType::Tunnel => "https://",
#[cfg(unix)] #[cfg(unix)]
NetworkStreamType::Unix => "http+unix://", NetworkStreamType::Unix => "http+unix://",
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
NetworkStreamType::Vsock => "http+vsock://", NetworkStreamType::Vsock => "http+vsock://",
} }
} }
@ -309,7 +329,11 @@ fn req_host<'a>(
} }
#[cfg(unix)] #[cfg(unix)]
NetworkStreamType::Unix => {} NetworkStreamType::Unix => {}
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
NetworkStreamType::Vsock => {} NetworkStreamType::Vsock => {}
} }
return Some(Cow::Borrowed(auth.as_str())); return Some(Cow::Borrowed(auth.as_str()));

View file

@ -35,5 +35,5 @@ tokio.workspace = true
url.workspace = true url.workspace = true
web-transport-proto.workspace = true web-transport-proto.workspace = true
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies] [target.'cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))'.dependencies]
tokio-vsock.workspace = true tokio-vsock.workspace = true

View file

@ -190,14 +190,22 @@ impl Resource for UnixStreamResource {
} }
} }
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
pub type VsockStreamResource = pub type VsockStreamResource =
FullDuplexResource<tokio_vsock::OwnedReadHalf, tokio_vsock::OwnedWriteHalf>; FullDuplexResource<tokio_vsock::OwnedReadHalf, tokio_vsock::OwnedWriteHalf>;
#[cfg(not(any(target_os = "linux", target_os = "macos")))] #[cfg(not(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
)))]
pub struct VsockStreamResource; pub struct VsockStreamResource;
#[cfg(not(any(target_os = "linux", target_os = "macos")))] #[cfg(not(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
)))]
impl VsockStreamResource { impl VsockStreamResource {
fn read(self: Rc<Self>, _data: &mut [u8]) -> AsyncResult<usize> { fn read(self: Rc<Self>, _data: &mut [u8]) -> AsyncResult<usize> {
unreachable!() unreachable!()

View file

@ -638,7 +638,7 @@ where
target_os = "linux" target_os = "linux"
))] ))]
socket_tmp.set_reuse_address(true)?; socket_tmp.set_reuse_address(true)?;
#[cfg(all(unix, not(target_os = "linux")))] #[cfg(all(unix, not(any(target_os = "android", target_os = "linux"))))]
socket_tmp.set_reuse_port(true)?; socket_tmp.set_reuse_port(true)?;
} }
let socket_addr = socket2::SockAddr::from(addr); let socket_addr = socket2::SockAddr::from(addr);
@ -696,7 +696,7 @@ where
net_listen_udp::<NP>(state, addr, reuse_address, loopback) net_listen_udp::<NP>(state, addr, reuse_address, loopback)
} }
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
#[op2(async, stack_trace)] #[op2(async, stack_trace)]
#[serde] #[serde]
pub async fn op_net_connect_vsock<NP>( pub async fn op_net_connect_vsock<NP>(
@ -744,7 +744,11 @@ where
)) ))
} }
#[cfg(not(any(target_os = "linux", target_os = "macos")))] #[cfg(not(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
)))]
#[op2] #[op2]
#[serde] #[serde]
pub fn op_net_connect_vsock<NP>() -> Result<(), NetError> pub fn op_net_connect_vsock<NP>() -> Result<(), NetError>
@ -754,7 +758,7 @@ where
Err(NetError::VsockUnsupported) Err(NetError::VsockUnsupported)
} }
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
#[op2(stack_trace)] #[op2(stack_trace)]
#[serde] #[serde]
pub fn op_net_listen_vsock<NP>( pub fn op_net_listen_vsock<NP>(
@ -787,7 +791,11 @@ where
Ok((rid, local_addr.cid(), local_addr.port())) Ok((rid, local_addr.cid(), local_addr.port()))
} }
#[cfg(not(any(target_os = "linux", target_os = "macos")))] #[cfg(not(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
)))]
#[op2] #[op2]
#[serde] #[serde]
pub fn op_net_listen_vsock<NP>() -> Result<(), NetError> pub fn op_net_listen_vsock<NP>() -> Result<(), NetError>
@ -797,7 +805,7 @@ where
Err(NetError::VsockUnsupported) Err(NetError::VsockUnsupported)
} }
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
#[op2(async)] #[op2(async)]
#[serde] #[serde]
pub async fn op_net_accept_vsock( pub async fn op_net_accept_vsock(
@ -836,7 +844,11 @@ pub async fn op_net_accept_vsock(
)) ))
} }
#[cfg(not(any(target_os = "linux", target_os = "macos")))] #[cfg(not(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
)))]
#[op2] #[op2]
#[serde] #[serde]
pub fn op_net_accept_vsock() -> Result<(), NetError> { pub fn op_net_accept_vsock() -> Result<(), NetError> {

View file

@ -257,7 +257,7 @@ macro_rules! network_stream {
} }
#[cfg(unix)] #[cfg(unix)]
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
network_stream!( network_stream!(
[ [
Tcp, Tcp,
@ -302,7 +302,11 @@ network_stream!(
); );
#[cfg(unix)] #[cfg(unix)]
#[cfg(not(any(target_os = "linux", target_os = "macos")))] #[cfg(not(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
)))]
network_stream!( network_stream!(
[ [
Tcp, Tcp,
@ -370,7 +374,7 @@ pub enum NetworkStreamAddress {
Ip(std::net::SocketAddr), Ip(std::net::SocketAddr),
#[cfg(unix)] #[cfg(unix)]
Unix(tokio::net::unix::SocketAddr), Unix(tokio::net::unix::SocketAddr),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
Vsock(tokio_vsock::VsockAddr), Vsock(tokio_vsock::VsockAddr),
Tunnel(crate::tunnel::TunnelAddr), Tunnel(crate::tunnel::TunnelAddr),
} }
@ -388,7 +392,7 @@ impl From<tokio::net::unix::SocketAddr> for NetworkStreamAddress {
} }
} }
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
impl From<tokio_vsock::VsockAddr> for NetworkStreamAddress { impl From<tokio_vsock::VsockAddr> for NetworkStreamAddress {
fn from(value: tokio_vsock::VsockAddr) -> Self { fn from(value: tokio_vsock::VsockAddr) -> Self {
NetworkStreamAddress::Vsock(value) NetworkStreamAddress::Vsock(value)
@ -413,7 +417,7 @@ pub enum TakeNetworkStreamError {
#[class("Busy")] #[class("Busy")]
#[error("Unix socket is currently in use")] #[error("Unix socket is currently in use")]
UnixBusy, UnixBusy,
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
#[class("Busy")] #[class("Busy")]
#[error("Vsock socket is currently in use")] #[error("Vsock socket is currently in use")]
VsockBusy, VsockBusy,
@ -427,7 +431,7 @@ pub enum TakeNetworkStreamError {
#[class(generic)] #[class(generic)]
#[error(transparent)] #[error(transparent)]
ReuniteUnix(#[from] tokio::net::unix::ReuniteError), ReuniteUnix(#[from] tokio::net::unix::ReuniteError),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
#[class(generic)] #[class(generic)]
#[error("Cannot reunite halves from different streams")] #[error("Cannot reunite halves from different streams")]
ReuniteVsock, ReuniteVsock,
@ -477,7 +481,7 @@ pub fn take_network_stream_resource(
return Ok(NetworkStream::Unix(unix_stream)); return Ok(NetworkStream::Unix(unix_stream));
} }
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
if let Ok(resource_rc) = if let Ok(resource_rc) =
resource_table.take::<crate::io::VsockStreamResource>(stream_rid) resource_table.take::<crate::io::VsockStreamResource>(stream_rid)
{ {

View file

@ -235,7 +235,7 @@ pub fn op_node_fs_constants() -> FsConstants {
constants constants
} }
#[cfg(target_os = "linux")] #[cfg(any(target_os = "android", target_os = "linux"))]
#[op2] #[op2]
#[serde] #[serde]
pub fn op_node_fs_constants() -> FsConstants { pub fn op_node_fs_constants() -> FsConstants {

View file

@ -37,5 +37,5 @@ thiserror.workspace = true
tokio.workspace = true tokio.workspace = true
tower-service.workspace = true tower-service.workspace = true
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies] [target.'cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))'.dependencies]
tokio-vsock.workspace = true tokio-vsock.workspace = true

View file

@ -524,9 +524,17 @@ mod hyper_client {
use opentelemetry_http::Response; use opentelemetry_http::Response;
use opentelemetry_http::ResponseExt; use opentelemetry_http::ResponseExt;
use tokio::net::TcpStream; use tokio::net::TcpStream;
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
use tokio_vsock::VsockAddr; use tokio_vsock::VsockAddr;
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
use tokio_vsock::VsockStream; use tokio_vsock::VsockStream;
use super::OtelSharedRuntime; use super::OtelSharedRuntime;
@ -545,7 +553,11 @@ mod hyper_client {
enum Connector { enum Connector {
Http(HttpsConnector<HttpConnector>), Http(HttpsConnector<HttpConnector>),
Tunnel(TunnelConnection), Tunnel(TunnelConnection),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
Vsock(VsockAddr), Vsock(VsockAddr),
} }
@ -554,7 +566,11 @@ mod hyper_client {
enum IO { enum IO {
Tls(#[pin] TokioIo<MaybeHttpsStream<TokioIo<TcpStream>>>), Tls(#[pin] TokioIo<MaybeHttpsStream<TokioIo<TcpStream>>>),
Tunnel(#[pin] TunnelStream), Tunnel(#[pin] TunnelStream),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
Vsock(#[pin] VsockStream), Vsock(#[pin] VsockStream),
} }
@ -567,7 +583,11 @@ mod hyper_client {
match self.project() { match self.project() {
IOProj::Tls(stream) => stream.poll_read(cx, buf), IOProj::Tls(stream) => stream.poll_read(cx, buf),
IOProj::Tunnel(stream) => stream.poll_read(cx, buf), IOProj::Tunnel(stream) => stream.poll_read(cx, buf),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
IOProj::Vsock(stream) => stream.poll_read(cx, buf), IOProj::Vsock(stream) => stream.poll_read(cx, buf),
} }
} }
@ -582,7 +602,11 @@ mod hyper_client {
match self.project() { match self.project() {
IOProj::Tls(stream) => stream.poll_write(cx, buf), IOProj::Tls(stream) => stream.poll_write(cx, buf),
IOProj::Tunnel(stream) => stream.poll_write(cx, buf), IOProj::Tunnel(stream) => stream.poll_write(cx, buf),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
IOProj::Vsock(stream) => stream.poll_write(cx, buf), IOProj::Vsock(stream) => stream.poll_write(cx, buf),
} }
} }
@ -594,7 +618,11 @@ mod hyper_client {
match self.project() { match self.project() {
IOProj::Tls(stream) => stream.poll_flush(cx), IOProj::Tls(stream) => stream.poll_flush(cx),
IOProj::Tunnel(stream) => stream.poll_flush(cx), IOProj::Tunnel(stream) => stream.poll_flush(cx),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
IOProj::Vsock(stream) => stream.poll_flush(cx), IOProj::Vsock(stream) => stream.poll_flush(cx),
} }
} }
@ -606,7 +634,11 @@ mod hyper_client {
match self.project() { match self.project() {
IOProj::Tls(stream) => stream.poll_shutdown(cx), IOProj::Tls(stream) => stream.poll_shutdown(cx),
IOProj::Tunnel(stream) => stream.poll_shutdown(cx), IOProj::Tunnel(stream) => stream.poll_shutdown(cx),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
IOProj::Vsock(stream) => stream.poll_shutdown(cx), IOProj::Vsock(stream) => stream.poll_shutdown(cx),
} }
} }
@ -615,7 +647,11 @@ mod hyper_client {
match self { match self {
IO::Tls(stream) => stream.is_write_vectored(), IO::Tls(stream) => stream.is_write_vectored(),
IO::Tunnel(stream) => stream.is_write_vectored(), IO::Tunnel(stream) => stream.is_write_vectored(),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
IO::Vsock(stream) => stream.is_write_vectored(), IO::Vsock(stream) => stream.is_write_vectored(),
} }
} }
@ -628,7 +664,11 @@ mod hyper_client {
match self.project() { match self.project() {
IOProj::Tls(stream) => stream.poll_write_vectored(cx, bufs), IOProj::Tls(stream) => stream.poll_write_vectored(cx, bufs),
IOProj::Tunnel(stream) => stream.poll_write_vectored(cx, bufs), IOProj::Tunnel(stream) => stream.poll_write_vectored(cx, bufs),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
IOProj::Vsock(stream) => stream.poll_write_vectored(cx, bufs), IOProj::Vsock(stream) => stream.poll_write_vectored(cx, bufs),
} }
} }
@ -639,7 +679,11 @@ mod hyper_client {
match self { match self {
Self::Tls(stream) => stream.connected(), Self::Tls(stream) => stream.connected(),
Self::Tunnel(_) => Connected::new().proxy(true), Self::Tunnel(_) => Connected::new().proxy(true),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
Self::Vsock(_) => Connected::new().proxy(true), Self::Vsock(_) => Connected::new().proxy(true),
} }
} }
@ -662,7 +706,11 @@ mod hyper_client {
match self { match self {
Self::Http(c) => c.poll_ready(cx).map_err(Into::into), Self::Http(c) => c.poll_ready(cx).map_err(Into::into),
Self::Tunnel(_) => Poll::Ready(Ok(())), Self::Tunnel(_) => Poll::Ready(Ok(())),
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
Self::Vsock(_) => Poll::Ready(Ok(())), Self::Vsock(_) => Poll::Ready(Ok(())),
} }
} }
@ -679,7 +727,11 @@ mod hyper_client {
let stream = listener.create_agent_stream().await?; let stream = listener.create_agent_stream().await?;
Ok(TokioIo::new(IO::Tunnel(stream))) Ok(TokioIo::new(IO::Tunnel(stream)))
} }
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
Self::Vsock(addr) => { Self::Vsock(addr) => {
let stream = VsockStream::connect(addr).await?; let stream = VsockStream::connect(addr).await?;
Ok(TokioIo::new(IO::Vsock(stream))) Ok(TokioIo::new(IO::Vsock(stream)))
@ -699,13 +751,21 @@ mod hyper_client {
let connector = if let Some(tunnel) = get_tunnel() { let connector = if let Some(tunnel) = get_tunnel() {
Connector::Tunnel(tunnel.clone()) Connector::Tunnel(tunnel.clone())
} else if let Ok(addr) = std::env::var("OTEL_DENO_VSOCK") { } else if let Ok(addr) = std::env::var("OTEL_DENO_VSOCK") {
#[cfg(not(any(target_os = "linux", target_os = "macos")))] #[cfg(not(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
)))]
{ {
let _ = addr; let _ = addr;
deno_core::anyhow::bail!("vsock is not supported on this platform") deno_core::anyhow::bail!("vsock is not supported on this platform")
} }
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "macos"
))]
{ {
let Some((cid, port)) = addr.split_once(':') else { let Some((cid, port)) = addr.split_once(':') else {
deno_core::anyhow::bail!("invalid vsock addr"); deno_core::anyhow::bail!("invalid vsock addr");

View file

@ -24,6 +24,16 @@ use crate::surface::GPUCanvasContext;
#[derive(Debug, thiserror::Error, deno_error::JsError)] #[derive(Debug, thiserror::Error, deno_error::JsError)]
pub enum ByowError { pub enum ByowError {
#[cfg(not(any(
target_os = "macos",
target_os = "windows",
target_os = "linux",
target_os = "freebsd",
target_os = "openbsd",
)))]
#[class(type)]
#[error("Unsupported platform")]
Unsupported,
#[class(type)] #[class(type)]
#[error( #[error(
"Cannot create surface outside of WebGPU context. Did you forget to call `navigator.gpu.requestAdapter()`?" "Cannot create surface outside of WebGPU context. Did you forget to call `navigator.gpu.requestAdapter()`?"
@ -360,6 +370,6 @@ fn raw_window(
_system: UnsafeWindowSurfaceSystem, _system: UnsafeWindowSurfaceSystem,
_window: *const c_void, _window: *const c_void,
_display: *const c_void, _display: *const c_void,
) -> Result<RawHandles, deno_error::JsErrorBox> { ) -> Result<RawHandles, ByowError> {
Err(deno_error::JsErrorBox::type_error("Unsupported platform")) Err(ByowError::Unsupported)
} }