diff --git a/Cargo.toml b/Cargo.toml index 6089f06..5352d31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -89,7 +89,7 @@ gtk-sys = { version = "0.18.0", features = ["v3_24"], optional = true } glib-sys = { version = "0.18.0", optional = true } gobject-sys = { version = "0.18.0", optional = true } -[target.'cfg(target_arch = "wasm32")'.dependencies] +[target.'cfg(target_family = "wasm")'.dependencies] wasm-bindgen = "0.2.69" js-sys = "0.3.46" web-sys = { version = "0.3.46", features = [ diff --git a/build.rs b/build.rs index 31f8732..8b06fa6 100644 --- a/build.rs +++ b/build.rs @@ -1,11 +1,14 @@ fn main() { let target_os = std::env::var("CARGO_CFG_TARGET_OS").expect("target OS not detected"); let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").expect("target ARCH not detected"); + let target_family = + std::env::var("CARGO_CFG_TARGET_FAMILY").expect("target FAMILY not detected"); + let is_wasm = target_family.split(',').any(|f| f == "wasm"); - match (target_arch.as_str(), target_os.as_str()) { - (_, "macos") => println!("cargo:rustc-link-lib=framework=AppKit"), - (_, "windows") => {} - ("wasm32", _) => {} + match target_os.as_str() { + "macos" => println!("cargo:rustc-link-lib=framework=AppKit"), + "windows" => {} + _ if is_wasm => {} _ => { let gtk = std::env::var_os("CARGO_FEATURE_GTK3").is_some(); let xdg = std::env::var_os("CARGO_FEATURE_XDG_PORTAL").is_some(); diff --git a/examples/async.rs b/examples/async.rs index c14a56d..7f9176f 100644 --- a/examples/async.rs +++ b/examples/async.rs @@ -8,7 +8,7 @@ fn main() { if let Some(file) = file { // If you are on native platform you can just get the path - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(target_family = "wasm"))] println!("{:?}", file.path()); // If you care about wasm support you just read() the file @@ -21,12 +21,12 @@ fn main() { use std::future::Future; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(target_family = "wasm"))] fn execute + Send + 'static>(f: F) { // this is stupid... use any executor of your choice instead std::thread::spawn(move || futures::executor::block_on(f)); } -#[cfg(target_arch = "wasm32")] +#[cfg(target_family = "wasm")] fn execute + 'static>(f: F) { wasm_bindgen_futures::spawn_local(f); } diff --git a/examples/save.rs b/examples/save.rs index a73c244..ccb0d0f 100644 --- a/examples/save.rs +++ b/examples/save.rs @@ -1,4 +1,4 @@ -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(target_family = "wasm"))] fn main() { let path = std::env::current_dir().unwrap(); @@ -10,7 +10,7 @@ fn main() { println!("The user choose: {:#?}", res); } -#[cfg(target_arch = "wasm32")] +#[cfg(target_family = "wasm")] fn main() { // On wasm only async dialogs are possible } diff --git a/examples/simple.rs b/examples/simple.rs index 2c7710c..f2e6ccf 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -1,4 +1,4 @@ -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(target_family = "wasm"))] fn main() { let path = std::env::current_dir().unwrap(); @@ -11,7 +11,7 @@ fn main() { println!("The user choose: {:#?}", res); } -#[cfg(target_arch = "wasm32")] +#[cfg(target_family = "wasm")] fn main() { // On wasm only async dialogs are possible } diff --git a/examples/winit-example/src/main.rs b/examples/winit-example/src/main.rs index 7dbac12..450112e 100755 --- a/examples/winit-example/src/main.rs +++ b/examples/winit-example/src/main.rs @@ -19,7 +19,7 @@ fn main() { let window = builder.build(&event_loop).unwrap(); - #[cfg(target_arch = "wasm32")] + #[cfg(target_family = "wasm")] { use winit::platform::web::WindowExtWebSys; @@ -41,9 +41,9 @@ fn main() { event_loop .run(move |event, target| match event { event::Event::UserEvent(name) => { - #[cfg(target_arch = "wasm32")] + #[cfg(target_family = "wasm")] alert(&name); - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(target_family = "wasm"))] println!("{}", name); } event::Event::WindowEvent { event, .. } => match event { @@ -205,23 +205,23 @@ fn main() { use std::future::Future; struct Executor { - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(target_family = "wasm"))] pool: futures::executor::ThreadPool, } impl Executor { fn new() -> Self { Self { - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(target_family = "wasm"))] pool: futures::executor::ThreadPool::new().unwrap(), } } - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(target_family = "wasm"))] fn execut + Send + 'static>(&self, f: F) { self.pool.spawn_ok(f); } - #[cfg(target_arch = "wasm32")] + #[cfg(target_family = "wasm")] fn execut + 'static>(&self, f: F) { wasm_bindgen_futures::spawn_local(f); } diff --git a/src/backend.rs b/src/backend.rs index a4edf24..a9ab5aa 100755 --- a/src/backend.rs +++ b/src/backend.rs @@ -1,7 +1,7 @@ use crate::message_dialog::MessageDialogResult; use crate::FileHandle; use std::future::Future; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(target_family = "wasm"))] use std::path::PathBuf; use std::pin::Pin; @@ -30,7 +30,7 @@ mod linux; mod gtk3; #[cfg(target_os = "macos")] mod macos; -#[cfg(target_arch = "wasm32")] +#[cfg(target_family = "wasm")] mod wasm; #[cfg(target_os = "windows")] mod win_cid; @@ -51,20 +51,20 @@ mod xdg_desktop_portal; // /// Dialog used to pick file/files -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(target_family = "wasm"))] pub trait FilePickerDialogImpl { fn pick_file(self) -> Option; fn pick_files(self) -> Option>; } /// Dialog used to save file -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(target_family = "wasm"))] pub trait FileSaveDialogImpl { fn save_file(self) -> Option; } /// Dialog used to pick folder -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(target_family = "wasm"))] pub trait FolderPickerDialogImpl { fn pick_folder(self) -> Option; fn pick_folders(self) -> Option>; @@ -86,9 +86,9 @@ pub trait MessageDialogImpl { // // Return type of async dialogs: -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(target_family = "wasm"))] pub type DialogFutureType = Pin + Send>>; -#[cfg(target_arch = "wasm32")] +#[cfg(target_family = "wasm")] pub type DialogFutureType = Pin>>; /// Dialog used to pick file/files @@ -98,7 +98,7 @@ pub trait AsyncFilePickerDialogImpl { } /// Dialog used to pick folder -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(target_family = "wasm"))] pub trait AsyncFolderPickerDialogImpl { fn pick_folder_async(self) -> DialogFutureType>; fn pick_folders_async(self) -> DialogFutureType>>; diff --git a/src/file_dialog.rs b/src/file_dialog.rs index 291e98f..e74c341 100755 --- a/src/file_dialog.rs +++ b/src/file_dialog.rs @@ -35,7 +35,7 @@ unsafe impl Sync for FileDialog {} impl FileDialog { /// New file dialog builder - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(target_family = "wasm"))] pub fn new() -> Self { Default::default() } @@ -121,13 +121,13 @@ impl FileDialog { } } -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(target_family = "wasm"))] use crate::backend::{FilePickerDialogImpl, FileSaveDialogImpl, FolderPickerDialogImpl}; #[cfg(target_os = "macos")] use crate::backend::FileOrFolderPickerDialogImpl; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(target_family = "wasm"))] impl FileDialog { /// Pick one file pub fn pick_file(self) -> Option { @@ -279,7 +279,7 @@ impl AsyncFileDialog { use crate::backend::AsyncFileOrFolderPickerDialogImpl; use crate::backend::AsyncFilePickerDialogImpl; use crate::backend::AsyncFileSaveDialogImpl; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(target_family = "wasm"))] use crate::backend::AsyncFolderPickerDialogImpl; use std::future::Future; @@ -295,7 +295,7 @@ impl AsyncFileDialog { AsyncFilePickerDialogImpl::pick_files_async(self.file_dialog) } - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(target_family = "wasm"))] /// Pick one folder /// /// Does not exist in `WASM32` @@ -303,7 +303,7 @@ impl AsyncFileDialog { AsyncFolderPickerDialogImpl::pick_folder_async(self.file_dialog) } - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(target_family = "wasm"))] /// Pick multiple folders /// /// Does not exist in `WASM32` diff --git a/src/file_handle/mod.rs b/src/file_handle/mod.rs index f7e4b9e..eece3c4 100644 --- a/src/file_handle/mod.rs +++ b/src/file_handle/mod.rs @@ -5,16 +5,16 @@ //! //! It should allow a user to treat web browser files same way as native files -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(target_family = "wasm"))] mod native; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(target_family = "wasm"))] pub use native::FileHandle; -#[cfg(target_arch = "wasm32")] +#[cfg(target_family = "wasm")] mod web; -#[cfg(target_arch = "wasm32")] +#[cfg(target_family = "wasm")] pub use web::FileHandle; -#[cfg(target_arch = "wasm32")] +#[cfg(target_family = "wasm")] pub(crate) use web::WasmFileHandleKind; #[cfg(test)] @@ -27,7 +27,7 @@ mod tests { let _ = FileHandle::read; #[cfg(feature = "file-handle-inner")] let _ = FileHandle::inner; - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(target_family = "wasm"))] let _ = FileHandle::path; } } diff --git a/src/lib.rs b/src/lib.rs index 8cffa07..8fe08ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -136,7 +136,7 @@ pub use file_handle::FileHandle; mod file_dialog; mod oneshot; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(target_family = "wasm"))] pub use file_dialog::FileDialog; pub use file_dialog::AsyncFileDialog;