Skip to content

Commit 0f15589

Browse files
fix(core): docs.rs on Windows and macOS (#3566)
Co-authored-by: chip <chip@chip.sh>
1 parent 55280bd commit 0f15589

File tree

24 files changed

+418
-547
lines changed

24 files changed

+418
-547
lines changed

.changes/fs-extract-api-feature.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
**Breaking change:** The `tauri::api::file::Extract` API is now available when the `fs-extract-api` feature is enabled.

core/tauri-codegen/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ uuid = { version = "0.8", features = [ "v4" ] }
3131
default = [ "compression" ]
3232
compression = [ "zstd", "tauri-utils/compression" ]
3333
isolation = [ "tauri-utils/isolation" ]
34+
__isolation-docs = [ "tauri-utils/__isolation-docs" ]
3435
shell-scope = [ "regex" ]
3536
config-json5 = [ "tauri-utils/config-json5" ]

core/tauri-codegen/src/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn load_csp(document: &mut NodeRef, key: &AssetKey, csp_hashes: &mut CspHashes)
5050
fn map_core_assets(
5151
options: &AssetOptions,
5252
) -> impl Fn(&AssetKey, &Path, &mut Vec<u8>, &mut CspHashes) -> Result<(), EmbeddedAssetsError> {
53-
#[cfg(feature = "isolation")]
53+
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
5454
let pattern = tauri_utils::html::PatternObject::from(&options.pattern);
5555
let csp = options.csp;
5656
move |key, path, input, csp_hashes| {
@@ -60,7 +60,7 @@ fn map_core_assets(
6060
if csp {
6161
load_csp(&mut document, key, csp_hashes);
6262

63-
#[cfg(feature = "isolation")]
63+
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
6464
if let tauri_utils::html::PatternObject::Isolation { .. } = &pattern {
6565
// create the csp for the isolation iframe styling now, to make the runtime less complex
6666
let mut hasher = Sha256::new();
@@ -78,7 +78,7 @@ fn map_core_assets(
7878
}
7979
}
8080

81-
#[cfg(feature = "isolation")]
81+
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
8282
fn map_isolation(
8383
_options: &AssetOptions,
8484
dir: PathBuf,
@@ -268,7 +268,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
268268

269269
let pattern = match &options.pattern {
270270
PatternKind::Brownfield => quote!(#root::Pattern::Brownfield(std::marker::PhantomData)),
271-
#[cfg(feature = "isolation")]
271+
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
272272
PatternKind::Isolation { dir } => {
273273
let dir = config_parent.join(dir);
274274
if !dir.exists() {

core/tauri-codegen/src/embedded_assets.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pub struct AssetOptions {
182182
pub(crate) csp: bool,
183183
pub(crate) pattern: PatternKind,
184184
pub(crate) freeze_prototype: bool,
185-
#[cfg(feature = "isolation")]
185+
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
186186
pub(crate) isolation_schema: String,
187187
}
188188

@@ -193,7 +193,7 @@ impl AssetOptions {
193193
csp: false,
194194
pattern,
195195
freeze_prototype: false,
196-
#[cfg(feature = "isolation")]
196+
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
197197
isolation_schema: format!("isolation-{}", uuid::Uuid::new_v4()),
198198
}
199199
}

core/tauri-macros/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ tauri-utils = { version = "1.0.0-rc.2", path = "../tauri-utils" }
2727
custom-protocol = [ ]
2828
compression = [ "tauri-codegen/compression" ]
2929
isolation = [ "tauri-codegen/isolation" ]
30+
__isolation-docs = [ "tauri-codegen/__isolation-docs" ]
3031
shell-scope = [ "tauri-codegen/shell-scope" ]
3132
config-json5 = [ "tauri-codegen/config-json5", "tauri-utils/config-json5" ]

core/tauri-runtime-wry/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ exclude = [ ".license_template", "CHANGELOG.md", "/target" ]
1313
readme = "README.md"
1414

1515
[dependencies]
16-
wry = { version = "0.13.2", default-features = false, features = [ "file-drop", "protocol" ] }
16+
wry = { version = "0.13.3", default-features = false, features = [ "file-drop", "protocol" ] }
1717
tauri-runtime = { version = "0.3.2", path = "../tauri-runtime" }
1818
tauri-utils = { version = "1.0.0-rc.2", path = "../tauri-utils" }
1919
uuid = { version = "0.8.2", features = [ "v4" ] }
@@ -40,3 +40,4 @@ macos-private-api = [
4040
"wry/transparent",
4141
"tauri-runtime/macos-private-api"
4242
]
43+
objc-exception = [ "wry/objc-exception" ]

core/tauri-utils/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ build = [ "proc-macro2", "quote" ]
4242
compression = [ "zstd" ]
4343
schema = [ "schemars" ]
4444
isolation = [ "aes-gcm", "ring", "once_cell" ]
45+
__isolation-docs = [ "aes-gcm", "once_cell" ]
4546
process-relaunch-dangerous-allow-symlink-macos = [ ]
4647
config-json5 = [ "json5" ]
4748
resources = [ "glob", "walkdir" ]

core/tauri-utils/src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ pub enum PatternKind {
15091509
/// Brownfield pattern.
15101510
Brownfield,
15111511
/// Isolation pattern. Recommended for security purposes.
1512-
#[cfg(feature = "isolation")]
1512+
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
15131513
Isolation {
15141514
/// The dir containing the index.html file that contains the secure isolation application.
15151515
dir: PathBuf,
@@ -1586,7 +1586,7 @@ impl TauriConfig {
15861586
if self.macos_private_api {
15871587
features.push("macos-private-api");
15881588
}
1589-
#[cfg(feature = "isolation")]
1589+
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
15901590
if let PatternKind::Isolation { .. } = self.pattern {
15911591
features.push("isolation");
15921592
}
@@ -2238,7 +2238,7 @@ mod build {
22382238

22392239
tokens.append_all(match self {
22402240
Self::Brownfield => quote! { #prefix::Brownfield },
2241-
#[cfg(feature = "isolation")]
2241+
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
22422242
Self::Isolation { dir } => {
22432243
let dir = path_buf_lit(dir);
22442244
quote! { #prefix::Isolation { dir: #dir } }

core/tauri-utils/src/html.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use html5ever::{interface::QualName, namespace_url, ns, tendril::TendrilSink, Lo
1010
pub use kuchiki::NodeRef;
1111
use kuchiki::{Attribute, ExpandedName};
1212
use serde::Serialize;
13-
#[cfg(feature = "isolation")]
13+
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
1414
use serialize_to_javascript::DefaultTemplate;
1515

1616
use crate::config::PatternKind;
17-
#[cfg(feature = "isolation")]
17+
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
1818
use crate::pattern::isolation::IsolationJavascriptCodegen;
1919

2020
/// The token used on the CSP tag content.
@@ -115,7 +115,7 @@ impl From<&PatternKind> for PatternObject {
115115
fn from(pattern_kind: &PatternKind) -> Self {
116116
match pattern_kind {
117117
PatternKind::Brownfield => Self::Brownfield,
118-
#[cfg(feature = "isolation")]
118+
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
119119
PatternKind::Isolation { .. } => Self::Isolation {
120120
side: IsolationSide::default(),
121121
},
@@ -142,7 +142,7 @@ impl Default for IsolationSide {
142142
/// Injects the Isolation JavaScript to a codegen time document.
143143
///
144144
/// Note: This function is not considered part of the stable API.
145-
#[cfg(feature = "isolation")]
145+
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
146146
pub fn inject_codegen_isolation_script(document: &mut NodeRef) {
147147
with_head(document, |head| {
148148
let script = NodeRef::new_element(QualName::new(None, ns!(html), "script".into()), None);

core/tauri-utils/src/pattern/isolation.rs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,47 @@ use std::string::FromUtf8Error;
1010
use aes_gcm::aead::Aead;
1111
use aes_gcm::{aead::NewAead, Aes256Gcm, Nonce};
1212
use once_cell::sync::OnceCell;
13-
use ring::error::Unspecified;
14-
use ring::rand::SystemRandom;
1513
use serialize_to_javascript::{default_template, Template};
1614

15+
#[cfg(not(feature = "isolation"))]
16+
mod ring_impl {
17+
#[cfg(not(feature = "__isolation-docs"))]
18+
compile_error!(
19+
"Isolation random number generator was used without enabling the `isolation` feature."
20+
);
21+
22+
pub struct Unspecified;
23+
24+
pub struct SystemRandom;
25+
26+
impl SystemRandom {
27+
pub fn new() -> Self {
28+
unimplemented!()
29+
}
30+
}
31+
32+
pub struct Random;
33+
34+
impl Random {
35+
pub fn expose(self) -> [u8; 32] {
36+
unimplemented!()
37+
}
38+
}
39+
40+
pub fn rand_generate(_rng: &SystemRandom) -> Result<Random, super::Error> {
41+
unimplemented!()
42+
}
43+
}
44+
45+
#[cfg(feature = "isolation")]
46+
mod ring_impl {
47+
pub use ring::error::Unspecified;
48+
pub use ring::rand::generate as rand_generate;
49+
pub use ring::rand::SystemRandom;
50+
}
51+
52+
use ring_impl::*;
53+
1754
/// Cryptographically secure pseudo-random number generator.
1855
static RNG: OnceCell<SystemRandom> = OnceCell::new();
1956

@@ -67,7 +104,7 @@ impl Debug for AesGcmPair {
67104
impl AesGcmPair {
68105
fn new() -> Result<Self, Error> {
69106
let rng = RNG.get_or_init(SystemRandom::new);
70-
let raw: [u8; 32] = ring::rand::generate(rng)?.expose();
107+
let raw: [u8; 32] = ring_impl::rand_generate(rng)?.expose();
71108
let key = aes_gcm::Key::from_slice(&raw);
72109
Ok(Self {
73110
raw,

0 commit comments

Comments
 (0)