Skip to content

Commit

Permalink
fix(docs): set the --cfg docsrs arg for docs.rs build (#8123)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Oct 28, 2023
1 parent 74d2464 commit 0601d5d
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ The code for Tauri Core is located in `[Tauri repo root]/core/tauri`, and the Ru
You can build the Rust documentation locally running the following script:

```bash
$ RUSTDOCFLAGS="--cfg doc_cfg" cargo +nightly doc --all-features --open
$ RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features --open
```

### Developing the JS API
Expand Down
11 changes: 10 additions & 1 deletion core/tauri-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ rust-version = { workspace = true }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = [ "--cfg", "doc_cfg" ]
default-target = "x86_64-unknown-linux-gnu"
targets = [
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-linux-android",
"x86_64-apple-ios"
]
rustc-args = [ "--cfg", "docsrs" ]
rustdoc-args = [ "--cfg", "docsrs" ]

[dependencies]
anyhow = "1"
Expand Down
2 changes: 1 addition & 1 deletion core/tauri-build/src/codegen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tauri_utils::config::{AppUrl, WindowUrl};

// TODO docs
/// A builder for generating a Tauri application context during compile time.
#[cfg_attr(doc_cfg, doc(cfg(feature = "codegen")))]
#[cfg_attr(docsrs, doc(cfg(feature = "codegen")))]
#[derive(Debug)]
pub struct CodegenContext {
dev: bool,
Expand Down
4 changes: 2 additions & 2 deletions core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
html_logo_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png",
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
)]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_cfg))]

use anyhow::Context;
pub use anyhow::Result;
Expand All @@ -37,7 +37,7 @@ pub mod mobile;
mod static_vcruntime;

#[cfg(feature = "codegen")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "codegen")))]
#[cfg_attr(docsrs, doc(cfg(feature = "codegen")))]
pub use codegen::context::CodegenContext;

fn copy_file(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion core/tauri-runtime-wry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = { workspace = true }
rust-version = { workspace = true }

[dependencies]
wry = { version = "0.34.1", default-features = false, features = [ "tao", "file-drop", "protocol" ] }
wry = { version = "0.34.2", default-features = false, features = [ "tao", "file-drop", "protocol" ] }
tauri-runtime = { version = "1.0.0-alpha.3", path = "../tauri-runtime" }
tauri-utils = { version = "2.0.0-alpha.9", path = "../tauri-utils" }
raw-window-handle = "0.5"
Expand Down
3 changes: 2 additions & 1 deletion core/tauri-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ rust-version = { workspace = true }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = [ "--cfg", "doc_cfg" ]
rustc-args = [ "--cfg", "docsrs" ]
rustdoc-args = [ "--cfg", "docsrs" ]
default-target = "x86_64-unknown-linux-gnu"
targets = [
"x86_64-pc-windows-msvc",
Expand Down
16 changes: 8 additions & 8 deletions core/tauri-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
html_logo_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png",
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
)]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_cfg))]

use raw_window_handle::RawDisplayHandle;
use serde::Deserialize;
Expand Down Expand Up @@ -176,7 +176,7 @@ pub struct RunIteration {

/// Application's activation policy. Corresponds to NSApplicationActivationPolicy.
#[cfg(target_os = "macos")]
#[cfg_attr(doc_cfg, doc(cfg(target_os = "macos")))]
#[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
#[non_exhaustive]
pub enum ActivationPolicy {
/// Corresponds to NSApplicationActivationPolicyRegular.
Expand Down Expand Up @@ -211,12 +211,12 @@ pub trait RuntimeHandle<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'st

/// Shows the application, but does not automatically focus it.
#[cfg(target_os = "macos")]
#[cfg_attr(doc_cfg, doc(cfg(target_os = "macos")))]
#[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
fn show(&self) -> Result<()>;

/// Hides the application.
#[cfg(target_os = "macos")]
#[cfg_attr(doc_cfg, doc(cfg(target_os = "macos")))]
#[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
fn hide(&self) -> Result<()>;

/// Finds an Android class in the project scope.
Expand Down Expand Up @@ -261,7 +261,7 @@ pub trait Runtime<T: UserEvent>: Debug + Sized + 'static {

/// Creates a new webview runtime on any thread.
#[cfg(any(windows, target_os = "linux"))]
#[cfg_attr(doc_cfg, doc(cfg(any(windows, target_os = "linux"))))]
#[cfg_attr(docsrs, doc(cfg(any(windows, target_os = "linux"))))]
fn new_any_thread(args: RuntimeInitArgs) -> Result<Self>;

/// Creates an `EventLoopProxy` that can be used to dispatch user events to the main event loop.
Expand All @@ -282,17 +282,17 @@ pub trait Runtime<T: UserEvent>: Debug + Sized + 'static {

/// Sets the activation policy for the application. It is set to `NSApplicationActivationPolicyRegular` by default.
#[cfg(target_os = "macos")]
#[cfg_attr(doc_cfg, doc(cfg(target_os = "macos")))]
#[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
fn set_activation_policy(&mut self, activation_policy: ActivationPolicy);

/// Shows the application, but does not automatically focus it.
#[cfg(target_os = "macos")]
#[cfg_attr(doc_cfg, doc(cfg(target_os = "macos")))]
#[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
fn show(&self);

/// Hides the application.
#[cfg(target_os = "macos")]
#[cfg_attr(doc_cfg, doc(cfg(target_os = "macos")))]
#[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
fn hide(&self);

/// Change the device event filter mode.
Expand Down
2 changes: 1 addition & 1 deletion core/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub trait WindowBuilder: WindowBuilderBase {
/// with alpha values different than `1.0` will produce a transparent window.
#[cfg(any(not(target_os = "macos"), feature = "macos-private-api"))]
#[cfg_attr(
doc_cfg,
docsrs,
doc(cfg(any(not(target_os = "macos"), feature = "macos-private-api")))
)]
#[must_use]
Expand Down
3 changes: 2 additions & 1 deletion core/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ features = [
"protocol-asset",
"test",
]
rustdoc-args = [ "--cfg", "doc_cfg" ]
rustc-args = [ "--cfg", "docsrs" ]
rustdoc-args = [ "--cfg", "docsrs" ]
default-target = "x86_64-unknown-linux-gnu"
targets = [
"x86_64-pc-windows-msvc",
Expand Down
24 changes: 12 additions & 12 deletions core/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,18 @@ pub enum RunEvent {
MainEventsCleared,
/// Emitted when the user wants to open the specified resource with the app.
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[cfg_attr(doc_cfg, doc(cfg(any(target_os = "macos", feature = "ios"))))]
#[cfg_attr(docsrs, doc(cfg(any(target_os = "macos", feature = "ios"))))]
Opened {
/// The URL of the resources that is being open.
urls: Vec<url::Url>,
},
/// An event from a menu item, could be on the window menu bar, application menu bar (on macOS) or tray icon menu.
#[cfg(desktop)]
#[cfg_attr(doc_cfg, doc(cfg(desktop)))]
#[cfg_attr(docsrs, doc(cfg(desktop)))]
MenuEvent(crate::menu::MenuEvent),
/// An event from a tray icon.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
TrayIconEvent(crate::tray::TrayIconEvent),
}

Expand Down Expand Up @@ -506,7 +506,7 @@ macro_rules! shared_app_impl {

/// Registers a global tray icon menu event listener.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
pub fn on_tray_icon_event<F: Fn(&AppHandle<R>, TrayIconEvent) + Send + Sync + 'static>(
&self,
handler: F,
Expand All @@ -523,7 +523,7 @@ macro_rules! shared_app_impl {
/// Gets the first tray icon registered,
/// usually the one configured in the Tauri configuration file.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
pub fn tray(&self) -> Option<TrayIcon<R>> {
self
.manager
Expand All @@ -540,7 +540,7 @@ macro_rules! shared_app_impl {
///
/// Note that dropping the returned icon, will cause the tray icon to disappear.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
pub fn remove_tray(&self) -> Option<TrayIcon<R>> {
let mut tray_icons = self.manager.inner.tray_icons.lock().unwrap();
if !tray_icons.is_empty() {
Expand All @@ -551,7 +551,7 @@ macro_rules! shared_app_impl {

/// Gets a tray icon using the provided id.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
pub fn tray_by_id<'a, I>(&self, id: &'a I) -> Option<TrayIcon<R>>
where
I: ?Sized,
Expand All @@ -572,7 +572,7 @@ macro_rules! shared_app_impl {
///
/// Note that dropping the returned icon, will cause the tray icon to disappear.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
pub fn remove_tray_by_id<'a, I>(&self, id: &'a I) -> Option<TrayIcon<R>>
where
I: ?Sized,
Expand Down Expand Up @@ -824,7 +824,7 @@ impl<R: Runtime> App<R> {
/// app.run(|_app_handle, _event| {});
/// ```
#[cfg(target_os = "macos")]
#[cfg_attr(doc_cfg, doc(cfg(target_os = "macos")))]
#[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
pub fn set_activation_policy(&mut self, activation_policy: ActivationPolicy) {
self
.runtime
Expand Down Expand Up @@ -1046,7 +1046,7 @@ impl<R: Runtime> Builder<R> {
///
/// - **macOS:** on macOS the application *must* be executed on the main thread, so this function is not exposed.
#[cfg(any(windows, target_os = "linux"))]
#[cfg_attr(doc_cfg, doc(cfg(any(windows, target_os = "linux"))))]
#[cfg_attr(docsrs, doc(cfg(any(windows, target_os = "linux"))))]
#[must_use]
pub fn any_thread(mut self) -> Self {
self.runtime_any_thread = true;
Expand Down Expand Up @@ -1176,7 +1176,7 @@ impl<R: Runtime> Builder<R> {
/// refers to a different `T`.
///
/// Managed state can be retrieved by any command handler via the
/// [`State`](crate::State) guard. In particular, if a value of type `T`
/// [`State`] guard. In particular, if a value of type `T`
/// is managed by Tauri, adding `State<T>` to the list of arguments in a
/// command handler instructs Tauri to retrieve the managed value.
/// Additionally, [`state`](crate::Manager#method.state) can be used to retrieve the value manually.
Expand Down Expand Up @@ -1859,7 +1859,7 @@ fn on_event_loop_event<R: Runtime, F: FnMut(&AppHandle<R>, RunEvent) + 'static>(

/// Make `Wry` the default `Runtime` for `Builder`
#[cfg(feature = "wry")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "wry")))]
#[cfg_attr(docsrs, doc(cfg(feature = "wry")))]
impl Default for Builder<crate::Wry> {
fn default() -> Self {
Self::new()
Expand Down
4 changes: 2 additions & 2 deletions core/tauri/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ pub enum Error {
/// Tray icon error.
#[error("tray icon error: {0}")]
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
Tray(#[from] tray_icon::Error),
/// Bad tray icon error.
#[error(transparent)]
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
BadTrayIcon(#[from] tray_icon::BadIcon),
/// Path does not have a parent.
#[error("path does not have a parent")]
Expand Down
26 changes: 13 additions & 13 deletions core/tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
)]
#![warn(missing_docs, rust_2018_idioms)]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_cfg))]

/// Setups the binding that initializes an iOS plugin.
#[cfg(target_os = "ios")]
Expand Down Expand Up @@ -97,19 +97,19 @@ pub mod scope;
mod state;

#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
pub mod tray;
pub use tauri_utils as utils;

pub use http;

/// A Tauri [`Runtime`] wrapper around wry.
#[cfg(feature = "wry")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "wry")))]
#[cfg_attr(docsrs, doc(cfg(feature = "wry")))]
pub type Wry = tauri_runtime_wry::Wry<EventLoopMessage>;

#[cfg(all(feature = "wry", target_os = "android"))]
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "wry", target_os = "android"))))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "wry", target_os = "android"))))]
#[doc(hidden)]
#[macro_export]
macro_rules! android_binding {
Expand Down Expand Up @@ -168,11 +168,11 @@ use std::{
};

#[cfg(feature = "wry")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "wry")))]
#[cfg_attr(docsrs, doc(cfg(feature = "wry")))]
pub use tauri_runtime_wry::webview_version;

#[cfg(target_os = "macos")]
#[cfg_attr(doc_cfg, doc(cfg(target_os = "macos")))]
#[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
pub use runtime::ActivationPolicy;

#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -251,7 +251,7 @@ pub enum EventLoopMessage {
MenuEvent(menu::MenuEvent),
/// An event from a menu item, could be on the window menu bar, application menu bar (on macOS) or tray icon menu.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
TrayIconEvent(tray::TrayIconEvent),
}

Expand Down Expand Up @@ -302,11 +302,11 @@ pub use pattern::Pattern;
pub enum Icon {
/// Icon from file path.
#[cfg(any(feature = "icon-ico", feature = "icon-png"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "icon-ico", feature = "icon-png"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "icon-ico", feature = "icon-png"))))]
File(std::path::PathBuf),
/// Icon from raw RGBA bytes. Width and height is parsed at runtime.
#[cfg(any(feature = "icon-ico", feature = "icon-png"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "icon-ico", feature = "icon-png"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "icon-ico", feature = "icon-png"))))]
Raw(Vec<u8>),
/// Icon from raw RGBA bytes.
Rgba {
Expand Down Expand Up @@ -454,15 +454,15 @@ impl<A: Assets> Context<A> {

/// The icon to use on the system tray UI.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[inline(always)]
pub fn tray_icon(&self) -> Option<&Icon> {
self.tray_icon.as_ref()
}

/// A mutable reference to the icon to use on the tray icon.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[inline(always)]
pub fn tray_icon_mut(&mut self) -> &mut Option<Icon> {
&mut self.tray_icon
Expand Down Expand Up @@ -513,7 +513,7 @@ impl<A: Assets> Context<A> {

/// Sets the app tray icon.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[inline(always)]
pub fn set_tray_icon(&mut self, icon: Icon) {
self.tray_icon.replace(icon);
Expand Down Expand Up @@ -859,7 +859,7 @@ pub(crate) mod sealed {
}

#[cfg(any(test, feature = "test"))]
#[cfg_attr(doc_cfg, doc(cfg(feature = "test")))]
#[cfg_attr(docsrs, doc(cfg(feature = "test")))]
pub mod test;

#[cfg(test)]
Expand Down
Loading

0 comments on commit 0601d5d

Please sign in to comment.