Skip to content

Commit

Permalink
fix(core): docs.rs on Windows and macOS (#3566)
Browse files Browse the repository at this point in the history
Co-authored-by: chip <chip@chip.sh>
  • Loading branch information
lucasfernog and chippers committed Mar 2, 2022
1 parent 55280bd commit 0f15589
Show file tree
Hide file tree
Showing 24 changed files with 418 additions and 547 deletions.
5 changes: 5 additions & 0 deletions .changes/fs-extract-api-feature.md
@@ -0,0 +1,5 @@
---
"tauri": patch
---

**Breaking change:** The `tauri::api::file::Extract` API is now available when the `fs-extract-api` feature is enabled.
1 change: 1 addition & 0 deletions core/tauri-codegen/Cargo.toml
Expand Up @@ -31,5 +31,6 @@ uuid = { version = "0.8", features = [ "v4" ] }
default = [ "compression" ]
compression = [ "zstd", "tauri-utils/compression" ]
isolation = [ "tauri-utils/isolation" ]
__isolation-docs = [ "tauri-utils/__isolation-docs" ]
shell-scope = [ "regex" ]
config-json5 = [ "tauri-utils/config-json5" ]
8 changes: 4 additions & 4 deletions core/tauri-codegen/src/context.rs
Expand Up @@ -50,7 +50,7 @@ fn load_csp(document: &mut NodeRef, key: &AssetKey, csp_hashes: &mut CspHashes)
fn map_core_assets(
options: &AssetOptions,
) -> impl Fn(&AssetKey, &Path, &mut Vec<u8>, &mut CspHashes) -> Result<(), EmbeddedAssetsError> {
#[cfg(feature = "isolation")]
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
let pattern = tauri_utils::html::PatternObject::from(&options.pattern);
let csp = options.csp;
move |key, path, input, csp_hashes| {
Expand All @@ -60,7 +60,7 @@ fn map_core_assets(
if csp {
load_csp(&mut document, key, csp_hashes);

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

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

let pattern = match &options.pattern {
PatternKind::Brownfield => quote!(#root::Pattern::Brownfield(std::marker::PhantomData)),
#[cfg(feature = "isolation")]
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
PatternKind::Isolation { dir } => {
let dir = config_parent.join(dir);
if !dir.exists() {
Expand Down
4 changes: 2 additions & 2 deletions core/tauri-codegen/src/embedded_assets.rs
Expand Up @@ -182,7 +182,7 @@ pub struct AssetOptions {
pub(crate) csp: bool,
pub(crate) pattern: PatternKind,
pub(crate) freeze_prototype: bool,
#[cfg(feature = "isolation")]
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
pub(crate) isolation_schema: String,
}

Expand All @@ -193,7 +193,7 @@ impl AssetOptions {
csp: false,
pattern,
freeze_prototype: false,
#[cfg(feature = "isolation")]
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
isolation_schema: format!("isolation-{}", uuid::Uuid::new_v4()),
}
}
Expand Down
1 change: 1 addition & 0 deletions core/tauri-macros/Cargo.toml
Expand Up @@ -27,5 +27,6 @@ tauri-utils = { version = "1.0.0-rc.2", path = "../tauri-utils" }
custom-protocol = [ ]
compression = [ "tauri-codegen/compression" ]
isolation = [ "tauri-codegen/isolation" ]
__isolation-docs = [ "tauri-codegen/__isolation-docs" ]
shell-scope = [ "tauri-codegen/shell-scope" ]
config-json5 = [ "tauri-codegen/config-json5", "tauri-utils/config-json5" ]
3 changes: 2 additions & 1 deletion core/tauri-runtime-wry/Cargo.toml
Expand Up @@ -13,7 +13,7 @@ exclude = [ ".license_template", "CHANGELOG.md", "/target" ]
readme = "README.md"

[dependencies]
wry = { version = "0.13.2", default-features = false, features = [ "file-drop", "protocol" ] }
wry = { version = "0.13.3", default-features = false, features = [ "file-drop", "protocol" ] }
tauri-runtime = { version = "0.3.2", path = "../tauri-runtime" }
tauri-utils = { version = "1.0.0-rc.2", path = "../tauri-utils" }
uuid = { version = "0.8.2", features = [ "v4" ] }
Expand All @@ -40,3 +40,4 @@ macos-private-api = [
"wry/transparent",
"tauri-runtime/macos-private-api"
]
objc-exception = [ "wry/objc-exception" ]
1 change: 1 addition & 0 deletions core/tauri-utils/Cargo.toml
Expand Up @@ -42,6 +42,7 @@ build = [ "proc-macro2", "quote" ]
compression = [ "zstd" ]
schema = [ "schemars" ]
isolation = [ "aes-gcm", "ring", "once_cell" ]
__isolation-docs = [ "aes-gcm", "once_cell" ]
process-relaunch-dangerous-allow-symlink-macos = [ ]
config-json5 = [ "json5" ]
resources = [ "glob", "walkdir" ]
6 changes: 3 additions & 3 deletions core/tauri-utils/src/config.rs
Expand Up @@ -1509,7 +1509,7 @@ pub enum PatternKind {
/// Brownfield pattern.
Brownfield,
/// Isolation pattern. Recommended for security purposes.
#[cfg(feature = "isolation")]
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
Isolation {
/// The dir containing the index.html file that contains the secure isolation application.
dir: PathBuf,
Expand Down Expand Up @@ -1586,7 +1586,7 @@ impl TauriConfig {
if self.macos_private_api {
features.push("macos-private-api");
}
#[cfg(feature = "isolation")]
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
if let PatternKind::Isolation { .. } = self.pattern {
features.push("isolation");
}
Expand Down Expand Up @@ -2238,7 +2238,7 @@ mod build {

tokens.append_all(match self {
Self::Brownfield => quote! { #prefix::Brownfield },
#[cfg(feature = "isolation")]
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
Self::Isolation { dir } => {
let dir = path_buf_lit(dir);
quote! { #prefix::Isolation { dir: #dir } }
Expand Down
8 changes: 4 additions & 4 deletions core/tauri-utils/src/html.rs
Expand Up @@ -10,11 +10,11 @@ use html5ever::{interface::QualName, namespace_url, ns, tendril::TendrilSink, Lo
pub use kuchiki::NodeRef;
use kuchiki::{Attribute, ExpandedName};
use serde::Serialize;
#[cfg(feature = "isolation")]
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
use serialize_to_javascript::DefaultTemplate;

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

/// The token used on the CSP tag content.
Expand Down Expand Up @@ -115,7 +115,7 @@ impl From<&PatternKind> for PatternObject {
fn from(pattern_kind: &PatternKind) -> Self {
match pattern_kind {
PatternKind::Brownfield => Self::Brownfield,
#[cfg(feature = "isolation")]
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
PatternKind::Isolation { .. } => Self::Isolation {
side: IsolationSide::default(),
},
Expand All @@ -142,7 +142,7 @@ impl Default for IsolationSide {
/// Injects the Isolation JavaScript to a codegen time document.
///
/// Note: This function is not considered part of the stable API.
#[cfg(feature = "isolation")]
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
pub fn inject_codegen_isolation_script(document: &mut NodeRef) {
with_head(document, |head| {
let script = NodeRef::new_element(QualName::new(None, ns!(html), "script".into()), None);
Expand Down
43 changes: 40 additions & 3 deletions core/tauri-utils/src/pattern/isolation.rs
Expand Up @@ -10,10 +10,47 @@ use std::string::FromUtf8Error;
use aes_gcm::aead::Aead;
use aes_gcm::{aead::NewAead, Aes256Gcm, Nonce};
use once_cell::sync::OnceCell;
use ring::error::Unspecified;
use ring::rand::SystemRandom;
use serialize_to_javascript::{default_template, Template};

#[cfg(not(feature = "isolation"))]
mod ring_impl {
#[cfg(not(feature = "__isolation-docs"))]
compile_error!(
"Isolation random number generator was used without enabling the `isolation` feature."
);

pub struct Unspecified;

pub struct SystemRandom;

impl SystemRandom {
pub fn new() -> Self {
unimplemented!()
}
}

pub struct Random;

impl Random {
pub fn expose(self) -> [u8; 32] {
unimplemented!()
}
}

pub fn rand_generate(_rng: &SystemRandom) -> Result<Random, super::Error> {
unimplemented!()
}
}

#[cfg(feature = "isolation")]
mod ring_impl {
pub use ring::error::Unspecified;
pub use ring::rand::generate as rand_generate;
pub use ring::rand::SystemRandom;
}

use ring_impl::*;

/// Cryptographically secure pseudo-random number generator.
static RNG: OnceCell<SystemRandom> = OnceCell::new();

Expand Down Expand Up @@ -67,7 +104,7 @@ impl Debug for AesGcmPair {
impl AesGcmPair {
fn new() -> Result<Self, Error> {
let rng = RNG.get_or_init(SystemRandom::new);
let raw: [u8; 32] = ring::rand::generate(rng)?.expose();
let raw: [u8; 32] = ring_impl::rand_generate(rng)?.expose();
let key = aes_gcm::Key::from_slice(&raw);
Ok(Self {
raw,
Expand Down
2 changes: 1 addition & 1 deletion core/tauri-utils/src/pattern/mod.rs
Expand Up @@ -3,5 +3,5 @@
// SPDX-License-Identifier: MIT

/// Handling the Tauri "Isolation" Pattern.
#[cfg(feature = "isolation")]
#[cfg(any(feature = "isolation", feature = "__isolation-docs"))]
pub mod isolation;
19 changes: 11 additions & 8 deletions core/tauri/Cargo.toml
Expand Up @@ -19,15 +19,14 @@ repository = "https://github.com/tauri-apps/tauri"
version = "1.0.0-rc.3"

[package.metadata.docs.rs]
default-features = false
no-default-features = true
features = [
"compression",
"wry",
"isolation",
"__isolation-docs",
"custom-protocol",
"api-all",
"cli",
"updater",
"__updater-docs",
"system-tray",
"devtools",
"dox"
Expand Down Expand Up @@ -63,7 +62,7 @@ serde_repr = "0.1"
state = "0.5"
tar = "0.4"
tempfile = "3"
zip = "0.5"
zip = { version = "0.5", optional = true }
ignore = "0.4"
either = "1.6"
flate2 = "1.0"
Expand Down Expand Up @@ -112,19 +111,23 @@ quickcheck = "1.0.3"
quickcheck_macros = "1.0.0"
serde = { version = "1.0", features = [ "derive" ] }
serde_json = "1.0"
tauri = { path = "." }
tauri = { path = ".", default-features = false, features = [ "wry" ] }
tokio-test = "0.4.2"
tokio = { version = "1.16", features = [ "full" ] }

[features]
default = [ "wry", "compression" ]
default = [ "wry", "compression", "objc-exception" ]
compression = [ "tauri-macros/compression", "tauri-utils/compression" ]
wry = [ "tauri-runtime-wry" ]
objc-exception = [ "tauri-runtime-wry/objc-exception" ]
isolation = [ "tauri-utils/isolation", "tauri-macros/isolation" ]
__isolation-docs = [ "tauri-utils/__isolation-docs", "tauri-macros/__isolation-docs" ]
custom-protocol = [ "tauri-macros/custom-protocol" ]
updater = [ "minisign-verify", "base64", "http-api", "dialog-ask" ]
updater = [ "minisign-verify", "base64", "http-api", "dialog-ask", "fs-extract-api" ]
__updater-docs = [ "minisign-verify", "base64", "http-api", "dialog-ask" ]
http-api = [ "attohttpc" ]
shell-open-api = [ "open", "regex", "tauri-macros/shell-scope" ]
fs-extract-api = [ "zip" ]
reqwest-client = [ "reqwest", "bytes" ]
command = [ "shared_child", "os_pipe", "memchr" ]
dialog = [ "rfd" ]
Expand Down
1 change: 1 addition & 0 deletions core/tauri/src/api/error.rs
Expand Up @@ -66,6 +66,7 @@ pub enum Error {
#[error("failed to walkdir: {0}")]
Ignore(#[from] ignore::Error),
/// ZIP error.
#[cfg(feature = "fs-extract-api")]
#[error(transparent)]
Zip(#[from] zip::result::ZipError),
/// Notification error.
Expand Down
2 changes: 2 additions & 0 deletions core/tauri/src/api/file.rs
Expand Up @@ -4,11 +4,13 @@

//! Types and functions related to file operations.

#[cfg(feature = "fs-extract-api")]
mod extract;
mod file_move;

use std::{fs, path::Path};

#[cfg(feature = "fs-extract-api")]
pub use extract::*;
pub use file_move::*;

Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/error.rs
Expand Up @@ -64,7 +64,7 @@ pub enum Error {
#[error("error encountered during setup hook: {0}")]
Setup(Box<dyn std::error::Error + Send>),
/// Tauri updater error.
#[cfg(feature = "updater")]
#[cfg(any(feature = "updater", feature = "__updater-docs"))]
#[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]
#[error("Updater: {0}")]
TauriUpdater(#[from] crate::updater::Error),
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/lib.rs
Expand Up @@ -158,7 +158,7 @@ pub use tauri_runtime as runtime;
pub mod scope;
pub mod settings;
mod state;
#[cfg(feature = "updater")]
#[cfg(any(feature = "updater", feature = "__updater-docs"))]
#[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]
pub mod updater;

Expand Down
30 changes: 20 additions & 10 deletions core/tauri/src/updater/core.rs
Expand Up @@ -3,8 +3,9 @@
// SPDX-License-Identifier: MIT

use super::error::{Error, Result};
#[cfg(feature = "updater")]
use crate::api::file::{ArchiveFormat, Extract, Move};
use crate::api::{
file::{ArchiveFormat, Extract, Move},
http::{ClientBuilder, HttpRequestBuilder},
version,
};
Expand All @@ -13,18 +14,21 @@ use http::StatusCode;
use minisign_verify::{PublicKey, Signature};
use tauri_utils::{platform::current_exe, Env};

#[cfg(feature = "updater")]
use std::io::Seek;
use std::{
collections::HashMap,
env,
io::{Cursor, Read, Seek},
io::{Cursor, Read},
path::{Path, PathBuf},
str::from_utf8,
};

#[cfg(feature = "updater")]
#[cfg(not(target_os = "macos"))]
use std::ffi::OsStr;

#[cfg(not(target_os = "windows"))]
#[cfg(all(feature = "updater", not(target_os = "windows")))]
use crate::api::file::Compression;

#[cfg(target_os = "windows")]
Expand Down Expand Up @@ -471,13 +475,16 @@ impl Update {
return Err(Error::MissingUpdaterSignature);
}

// we copy the files depending of the operating system
// we run the setup, appimage re-install or overwrite the
// macos .app
#[cfg(target_os = "windows")]
copy_files_and_run(archive_buffer, extract_path, self.with_elevated_task)?;
#[cfg(not(target_os = "windows"))]
copy_files_and_run(archive_buffer, extract_path)?;
#[cfg(feature = "updater")]
{
// we copy the files depending of the operating system
// we run the setup, appimage re-install or overwrite the
// macos .app
#[cfg(target_os = "windows")]
copy_files_and_run(archive_buffer, extract_path, self.with_elevated_task)?;
#[cfg(not(target_os = "windows"))]
copy_files_and_run(archive_buffer, extract_path)?;
}
// We are done!
Ok(())
}
Expand All @@ -493,6 +500,7 @@ impl Update {
// We should have an AppImage already installed to be able to copy and install
// the extract_path is the current AppImage path
// tmp_dir is where our new AppImage is found
#[cfg(feature = "updater")]
#[cfg(target_os = "linux")]
fn copy_files_and_run<R: Read + Seek>(archive_buffer: R, extract_path: &Path) -> Result {
let tmp_dir = tempfile::Builder::new()
Expand Down Expand Up @@ -538,6 +546,7 @@ fn copy_files_and_run<R: Read + Seek>(archive_buffer: R, extract_path: &Path) ->

// ## EXE
// Update server can provide a custom EXE (installer) who can run any task.
#[cfg(feature = "updater")]
#[cfg(target_os = "windows")]
#[allow(clippy::unnecessary_wraps)]
fn copy_files_and_run<R: Read + Seek>(
Expand Down Expand Up @@ -639,6 +648,7 @@ fn copy_files_and_run<R: Read + Seek>(
// │ └── Contents # Application contents...
// │ └── ...
// └── ...
#[cfg(feature = "updater")]
#[cfg(target_os = "macos")]
fn copy_files_and_run<R: Read + Seek>(archive_buffer: R, extract_path: &Path) -> Result {
let mut extracted_files: Vec<PathBuf> = Vec::new();
Expand Down

0 comments on commit 0f15589

Please sign in to comment.