Skip to content

Commit

Permalink
Don't re-export unstable wasi features on stable Rust. (#589)
Browse files Browse the repository at this point in the history
* Don't re-export unstable wasi features on stable Rust.

Avoid depending on `wasi_ext` features when compiling for wasm32-wasi on
stable Rust.

* Disable `unused_imports` imports on WASI and Redox.

* Don't test --all-targets on WASI for now.

* Don't test wasm32-wasi on Rust 1.48.
  • Loading branch information
sunfishcode committed Apr 3, 2023
1 parent c4694f4 commit d013a81
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
sparcv9-sun-solaris
aarch64-linux-android
aarch64-apple-ios
wasm32-wasi
- if: matrix.rust != '1.48'
run: rustup target add x86_64-unknown-fuchsia
- if: matrix.rust == '1.48'
Expand Down Expand Up @@ -132,6 +133,10 @@ jobs:
- run: cargo check --workspace --release -vv --target=sparcv9-sun-solaris --features=all-apis --all-targets
- run: cargo check --workspace --release -vv --target=aarch64-apple-ios --features=all-apis --all-targets
- run: cargo check --workspace --release -vv --target=aarch64-linux-android --features=all-apis --all-targets
# Omit --all-targets for WASI until all the dev-dependencies support WASI
# on stable.
- if: matrix.rust != '1.48'
run: cargo check --workspace --release -vv --target=wasm32-wasi --features=all-apis

check_no_default_features:
name: Check --no-default-features
Expand Down
7 changes: 5 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() {
let arch = var("CARGO_CFG_TARGET_ARCH").unwrap();
let asm_name = format!("{}/{}.s", OUTLINE_PATH, arch);
let asm_name_present = std::fs::metadata(&asm_name).is_ok();
let os_name = var("CARGO_CFG_TARGET_OS").unwrap();
let target_os = var("CARGO_CFG_TARGET_OS").unwrap();
let pointer_width = var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap();
let endian = var("CARGO_CFG_TARGET_ENDIAN").unwrap();

Expand Down Expand Up @@ -69,7 +69,7 @@ fn main() {
// install the toolchain for it.
if feature_use_libc
|| cfg_use_libc
|| os_name != "linux"
|| target_os != "linux"
|| !asm_name_present
|| is_unsupported_abi
|| miri
Expand Down Expand Up @@ -106,6 +106,9 @@ fn main() {
use_feature("thumb_mode");
}

if target_os == "wasi" {
use_feature_or_nothing("wasi_ext");
}
println!("cargo:rerun-if-env-changed=CARGO_CFG_RUSTIX_USE_EXPERIMENTAL_ASM");
println!("cargo:rerun-if-env-changed=CARGO_CFG_RUSTIX_USE_LIBC");

Expand Down
5 changes: 1 addition & 4 deletions src/fs/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::backend;

pub use crate::io::FdFlags;
pub use backend::fs::types::{Access, Mode, OFlags};
pub use backend::fs::types::{Access, Dev, Mode, OFlags};

#[cfg(not(target_os = "redox"))]
pub use backend::fs::types::AtFlags;
Expand All @@ -14,7 +14,4 @@ pub use backend::fs::types::{CloneFlags, CopyfileFlags};
#[cfg(any(target_os = "android", target_os = "linux"))]
pub use backend::fs::types::{MountFlags, MountPropagationFlags, RenameFlags, ResolveFlags};

#[cfg(not(target_os = "redox"))]
pub use backend::fs::types::Dev;

pub use backend::time::types::{Nsecs, Secs, Timespec};
2 changes: 1 addition & 1 deletion src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,5 @@ pub use statx::{statx, Statx, StatxFlags, StatxTimestamp};
#[cfg(unix)]
pub use std::os::unix::fs::{DirEntryExt, FileExt, FileTypeExt, MetadataExt, OpenOptionsExt};
#[cfg(feature = "std")]
#[cfg(target_os = "wasi")]
#[cfg(all(wasi_ext, target_os = "wasi"))]
pub use std::os::wasi::fs::{DirEntryExt, FileExt, FileTypeExt, MetadataExt, OpenOptionsExt};
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
#![cfg_attr(linux_raw, deny(unsafe_code))]
#![cfg_attr(rustc_attrs, feature(rustc_attrs))]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![cfg_attr(all(target_os = "wasi", feature = "std"), feature(wasi_ext))]
#![cfg_attr(all(wasi_ext, target_os = "wasi", feature = "std"), feature(wasi_ext))]
#![cfg_attr(
all(linux_raw, naked_functions, target_arch = "x86"),
feature(naked_functions)
Expand All @@ -123,6 +123,9 @@
#![allow(clippy::unnecessary_cast)]
// It is common in linux and libc APIs for types to vary between platforms.
#![allow(clippy::useless_conversion)]
// Redox and WASI have enough differences that it isn't worth
// precisely conditionallizing all the `use`s for them.
#![cfg_attr(any(target_os = "redox", target_os = "wasi"), allow(unused_imports))]

#[cfg(not(feature = "rustc-dep-of-std"))]
extern crate alloc;
Expand Down
2 changes: 1 addition & 1 deletion tests/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn test_backends() {

#[cfg(windows)]
let libc_dep = "windows-sys";
#[cfg(unix)]
#[cfg(any(unix, target_os = "wasi"))]
let libc_dep = "libc";

// Test the use-libc crate, which enables the "use-libc" cargo feature.
Expand Down

0 comments on commit d013a81

Please sign in to comment.