feat: improvements to support hyphens in crate name (#5989)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
Amr Bashir 2023-01-06 19:31:48 +02:00 committed by GitHub
parent 2c4a0bbd1f
commit 50f6dd87b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 660 additions and 762 deletions

View File

@ -0,0 +1,6 @@
---
"cli.rs": patch
"cli.js": patch
---
Add support to custom and kebab case library names for mobile apps.

View File

@ -36,7 +36,7 @@ pub fn entry_point(_attributes: TokenStream, item: TokenStream) -> TokenStream {
let domain = get_env_var("TAURI_ANDROID_PACKAGE_PREFIX", |r| r, &mut error, &function);
let app_name = get_env_var(
"CARGO_PKG_NAME",
|r| r.replace('_', "_1"),
|r| r.replace('-', "_"),
&mut error,
&function,
);

View File

@ -13,7 +13,7 @@ exclude = [ "CHANGELOG.md", "/target" ]
readme = "README.md"
[dependencies]
wry = { version = "0.23.4", default-features = false, features = [ "file-drop", "protocol" ] }
wry = { git = "https://github.com/tauri-apps/wry", branch = "dev", default-features = false, features = [ "file-drop", "protocol" ] }
tauri-runtime = { version = "0.13.0-alpha.0", path = "../tauri-runtime" }
tauri-utils = { version = "2.0.0-alpha.0", path = "../tauri-utils" }
uuid = { version = "1", features = [ "v4" ] }

View File

@ -79,6 +79,7 @@ pub use wry::application::platform::macos::{
};
use std::{
borrow::Cow,
cell::RefCell,
collections::{
hash_map::Entry::{Occupied, Vacant},
@ -284,7 +285,7 @@ impl From<&WryRequest<Vec<u8>>> for HttpRequestWrapper {
}
// response
struct HttpResponseWrapper(WryResponse<Vec<u8>>);
struct HttpResponseWrapper(WryResponse<Cow<'static, [u8]>>);
impl From<HttpResponse> for HttpResponseWrapper {
fn from(response: HttpResponse) -> Self {
let (parts, body) = response.into_parts();

View File

@ -7,7 +7,7 @@ use super::{
status::StatusCode,
version::Version,
};
use std::fmt;
use std::{borrow::Cow, fmt};
type Result<T> = core::result::Result<T, Box<dyn std::error::Error>>;
@ -33,7 +33,7 @@ type Result<T> = core::result::Result<T, Box<dyn std::error::Error>>;
///
pub struct Response {
head: ResponseParts,
body: Vec<u8>,
body: Cow<'static, [u8]>,
}
/// Component parts of an HTTP `Response`
@ -67,7 +67,7 @@ pub struct Builder {
impl Response {
/// Creates a new blank `Response` with the body
#[inline]
pub fn new(body: Vec<u8>) -> Response {
pub fn new(body: Cow<'static, [u8]>) -> Response {
Response {
head: ResponseParts::new(),
body,
@ -81,7 +81,7 @@ impl Response {
/// This API is used internally. It may have breaking changes in the future.
#[inline]
#[doc(hidden)]
pub fn into_parts(self) -> (ResponseParts, Vec<u8>) {
pub fn into_parts(self) -> (ResponseParts, Cow<'static, [u8]>) {
(self.head, self.body)
}
@ -129,13 +129,13 @@ impl Response {
/// Returns a mutable reference to the associated HTTP body.
#[inline]
pub fn body_mut(&mut self) -> &mut Vec<u8> {
pub fn body_mut(&mut self) -> &mut Cow<'static, [u8]> {
&mut self.body
}
/// Returns a reference to the associated HTTP body.
#[inline]
pub fn body(&self) -> &Vec<u8> {
pub fn body(&self) -> &Cow<'static, [u8]> {
&self.body
}
}
@ -143,7 +143,7 @@ impl Response {
impl Default for Response {
#[inline]
fn default() -> Response {
Response::new(Vec::new())
Response::new(Default::default())
}
}
@ -280,8 +280,11 @@ impl Builder {
/// .body(Vec::new())
/// .unwrap();
/// ```
pub fn body(self, body: Vec<u8>) -> Result<Response> {
self.inner.map(move |head| Response { head, body })
pub fn body(self, body: impl Into<Cow<'static, [u8]>>) -> Result<Response> {
self.inner.map(move |head| Response {
head,
body: body.into(),
})
}
// private

View File

@ -60,7 +60,7 @@ state = "0.5"
tar = "0.4.38"
tempfile = "3"
zip = { version = "0.6", default-features = false, optional = true }
ignore = "0.4"
ignore = "=0.4.18"
flate2 = "1.0"
http = "0.2"
dirs-next = "2.0"

View File

@ -901,7 +901,7 @@ impl<R: Runtime> WindowManager<R> {
struct CachedResponse {
status: http::StatusCode,
headers: http::HeaderMap,
body: Vec<u8>,
body: Cow<'static, [u8]>,
}
#[cfg(dev)]
@ -951,7 +951,7 @@ impl<R: Runtime> WindowManager<R> {
let response = CachedResponse {
status,
headers,
body,
body: body.into(),
};
response_cache_.insert(url.clone(), response);
response_cache_.get(&url).unwrap()
@ -988,7 +988,7 @@ impl<R: Runtime> WindowManager<R> {
let response_csp = String::from_utf8_lossy(response_csp.as_bytes());
let html = String::from_utf8_lossy(response.body());
let body = html.replacen(tauri_utils::html::CSP_TOKEN, &response_csp, 1);
*response.body_mut() = body.as_bytes().to_vec();
*response.body_mut() = body.as_bytes().to_vec().into();
}
Ok(response)
})

View File

@ -895,7 +895,7 @@ fn copy_files_and_run<R: Read + Seek>(archive_buffer: R, extract_path: &Path) ->
})?;
let _ = std::process::Command::new("touch")
.arg(&extract_path)
.arg(extract_path)
.status();
Ok(())

View File

@ -94,7 +94,7 @@ fn bundle_path(root_dir: &Path, version: &str) -> PathBuf {
#[cfg(target_os = "macos")]
fn bundle_path(root_dir: &Path, _version: &str) -> PathBuf {
root_dir.join(format!("target/debug/bundle/macos/app-updater.app"))
root_dir.join("target/debug/bundle/macos/app-updater.app")
}
#[cfg(target_os = "ios")]

1241
tooling/cli/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -39,7 +39,7 @@ name = "cargo-tauri"
path = "src/main.rs"
[dependencies]
tauri-mobile = { version = "0.1.4", default-features = false }
tauri-mobile = { git = "https://github.com/tauri-apps/tauri-mobile", branch = "dev", default-features = false }
textwrap = { version = "0.11.0", features = [ "term_size" ] }
jsonrpsee = { version = "0.16", features = [ "client", "server" ] }
thiserror = "1"
@ -73,7 +73,7 @@ heck = "0.4"
dialoguer = "0.10"
url = { version = "2.3", features = [ "serde" ] }
os_pipe = "1"
ignore = "0.4"
ignore = "=0.4.18"
ctrlc = "3.2"
log = { version = "0.4.17", features = [ "kv_unstable", "kv_unstable_std" ] }
env_logger = "0.9.1"

View File

@ -45,6 +45,9 @@
"jest-transform-toml": "1.0.0",
"prettier": "2.8.1"
},
"resolutions": {
"json5": "2.2.3"
},
"engines": {
"node": ">= 10"
},

View File

@ -1822,17 +1822,10 @@ json-parse-even-better-errors@^2.3.0:
resolved "https://registry.yarnpkg.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz#7c47805a94319928e05777405dc12e1f7a4ee02d"
integrity sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==
json5@^2.1.2:
version "2.2.0"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.0.tgz#2dfefe720c6ba525d9ebd909950f0515316c89a3"
integrity sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==
dependencies:
minimist "^1.2.5"
json5@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.1.tgz#655d50ed1e6f95ad1a3caababd2b0efda10b395c"
integrity sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==
json5@2.2.3, json5@^2.1.2, json5@^2.2.1:
version "2.2.3"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"
integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==
jsonfile@^6.0.1:
version "6.1.0"
@ -1911,11 +1904,6 @@ minimatch@^3.0.4:
dependencies:
brace-expansion "^1.1.7"
minimist@^1.2.5:
version "1.2.6"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44"
integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==
ms@2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"

View File

@ -328,7 +328,7 @@ fn png(source: &DynamicImage, out_dir: &Path) -> Result<()> {
|_app, config, _metadata, _cli_options| {
let android_out = out_dir.parent().unwrap().join(format!(
"gen/android/{}/app/src/main/res/",
config.app().name()
config.app().name_snake()
));
let out = if android_out.exists() {
android_out

View File

@ -37,6 +37,7 @@ pub trait AppSettings {
target: &str,
) -> crate::Result<Vec<tauri_bundler::BundleBinary>>;
fn app_name(&self) -> Option<String>;
fn lib_name(&self) -> Option<String>;
fn get_bundler_settings(
&self,

View File

@ -772,6 +772,18 @@ impl AppSettings for RustAppSettings {
.and_then(|n| n.as_str())
.map(|n| n.to_string())
}
fn lib_name(&self) -> Option<String> {
self
.manifest
.inner
.as_table()
.get("lib")
.and_then(|p| p.as_table())
.and_then(|p| p.get("name"))
.and_then(|n| n.as_str())
.map(|n| n.to_string())
}
}
impl RustAppSettings {

View File

@ -107,8 +107,11 @@ pub fn get_config(
..Default::default()
};
set_var("WRY_ANDROID_REVERSED_DOMAIN", app.reverse_domain());
set_var("WRY_ANDROID_APP_NAME_SNAKE_CASE", app.name());
set_var(
"WRY_ANDROID_PACKAGE",
format!("{}.{}", app.reverse_domain(), app.name_snake()),
);
set_var("WRY_ANDROID_LIBRARY", app.lib_name());
set_var(
"WRY_ANDROID_KOTLIN_FILES_OUT_DIR",
config
@ -117,7 +120,7 @@ pub fn get_config(
.join(format!(
"java/{}/{}",
app.reverse_domain().replace('.', "/"),
app.name()
app.name_snake()
))
.join("generated"),
);

View File

@ -42,7 +42,7 @@ pub fn gen(
Path::new(&os::replace_path_separator(
util::relativize_path(
config.app().root_dir(),
config.project_dir().join(config.app().name()),
config.project_dir().join(config.app().name_snake()),
)
.into_os_string(),
)),
@ -83,7 +83,7 @@ pub fn gen(
map.insert("windows", cfg!(windows));
let domain = config.app().reverse_domain().replace('.', "/");
let package_path = format!("java/{}/{}", domain, config.app().name());
let package_path = format!("java/{}/{}", domain, config.app().name_snake());
map.insert("package-path", &package_path);

View File

@ -6,7 +6,6 @@ use crate::{
};
use clap::Parser;
use heck::AsSnakeCase;
use tauri_mobile::{apple::target::Target, opts::Profile, util};
use std::{collections::HashMap, ffi::OsStr, path::PathBuf};
@ -188,7 +187,7 @@ pub fn command(options: Options) -> Result<()> {
})?;
let out_dir = bin_path.parent().unwrap();
let lib_path = out_dir.join(format!("lib{}.a", AsSnakeCase(config.app().name())));
let lib_path = out_dir.join(format!("lib{}.a", config.app().lib_name()));
if !lib_path.exists() {
return Err(anyhow::anyhow!("Library not found at {}. Make sure your Cargo.toml file has a [lib] block with `crate-type = [\"staticlib\", \"cdylib\", \"rlib\"]`", lib_path.display()));
}
@ -201,7 +200,7 @@ pub fn command(options: Options) -> Result<()> {
format!(
"gen/apple/Externals/{rust_triple}/{}/lib{}.a",
profile.as_str(),
AsSnakeCase(config.app().name())
config.app().lib_name()
),
)?;
}

View File

@ -229,9 +229,11 @@ fn get_app(config: &TauriConfig) -> App {
.expect("failed to load interface");
let app_name = interface.app_settings().app_name().unwrap_or(app_name);
let lib_name = interface.app_settings().lib_name();
let raw = RawAppConfig {
name: app_name,
lib_name,
stylized_name: config.package.product_name.clone(),
domain,
asset_dir: None,

View File

@ -11,6 +11,7 @@ rust-version = "1.59"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "app_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
@ -22,9 +23,7 @@ serde = { version = "1.0", features = ["derive"] }
tauri = {{{ tauri_dep }}}
[features]
# by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
default = [ "custom-protocol" ]
# this feature is used for production builds where `devPath` points to the filesystem
default = []
# this feature is used for production builds or when `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = [ "tauri/custom-protocol" ]

View File

@ -1,8 +0,0 @@
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
pub fn main() {
app::AppBuilder::new().run();
}

View File

@ -1,41 +1,7 @@
use tauri::App;
#[cfg(mobile)]
mod mobile;
#[cfg(mobile)]
pub use mobile::*;
pub type SetupHook = Box<dyn FnOnce(&mut App) -> Result<(), Box<dyn std::error::Error>> + Send>;
#[derive(Default)]
pub struct AppBuilder {
setup: Option<SetupHook>,
}
impl AppBuilder {
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn setup<F>(mut self, setup: F) -> Self
where
F: FnOnce(&mut App) -> Result<(), Box<dyn std::error::Error>> + Send + 'static,
{
self.setup.replace(Box::new(setup));
self
}
pub fn run(self) {
let setup = self.setup;
tauri::Builder::default()
.setup(move |app| {
if let Some(setup) = setup {
(setup)(app)?;
}
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@ -1,7 +1,9 @@
#[cfg(desktop)]
mod desktop;
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
fn main() {
#[cfg(desktop)]
desktop::main();
app_lib::run();
}

View File

@ -1,4 +0,0 @@
#[tauri::mobile_entry_point]
fn main() {
super::AppBuilder::new().run()
}