Skip to content

Commit

Permalink
refactor!: consistent environment variables
Browse files Browse the repository at this point in the history
ref: #7756
  • Loading branch information
amrbashir committed Oct 3, 2023
1 parent d735324 commit 72fb8cb
Show file tree
Hide file tree
Showing 21 changed files with 138 additions and 101 deletions.
16 changes: 16 additions & 0 deletions .changes/cli-env-vars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'tauri-cli': 'major:breaking'
'@tauri-apps/cli': 'major:breaking'
---

Changed a number of environment variables used by tauri CLI for consistency and clarity:

- `TAURI_PRIVATE_KEY` -> `TAURI_SIGNINING_PRIVATE_KEY`
- `TAURI_KEY_PASSWORD` -> `TAURI_SIGNINING_PRIVATE_KEY_PASSWORD `
- `TAURI_SKIP_DEVSERVER_CHECK` -> `TAURI_CLI_NO_DEV_SERVER_WAIT`
- `TAURI_DEV_SERVER_PORT` -> `TAURI_CLI_PORT`
- `TAURI_PATH_DEPTH` -> `TAURI_CLI_CONFIG_DEPTH`
- `TAURI_FIPS_COMPLIANT` -> `TAURI_BUNDLER_WIX_FIPS_COMPLIANT`
- `TAURI_DEV_WATCHER_IGNORE_FILE` -> `TAURI_CLI_WATCHER_IGNORE_FILENAME`
- `TAURI_TRAY` -> `TAURI_LINUX_AYATANA_APPINDICATOR`
- `TAURI_APPLE_DEVELOPMENT_TEAM` -> `APPLE_DEVELOPMENT_TEAM`
6 changes: 6 additions & 0 deletions .changes/cli-no-dev-server-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri-cli': 'minor'
'@tauri-apps/cli': 'minor'
---

Add `--no-dev-server-wait` option to skip waiting for the dev server to start when using `tauri dev`.
6 changes: 6 additions & 0 deletions .changes/cli-removed-new-version-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri-cli': 'major:breaking'
'@tauri-apps/cli': 'major:breaking'
---

Removed checking for a new version of the CLI.
16 changes: 16 additions & 0 deletions .changes/tauri-env-vars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'tauri': 'major:breaking'
---

Changed a number of environment variables used by tauri for consistency and clarity:

- `TAURI_AUTOMATION` -> `TAURI_WEBVIEW_AUTOMATION`
- `TAURI_PRIVATE_KEY` -> `TAURI_SIGNINING_PRIVATE_KEY`
- `TAURI_KEY_PASSWORD` -> `TAURI_SIGNINING_PRIVATE_KEY_PASSWORD `
- `TAURI_SKIP_DEVSERVER_CHECK` -> `TAURI_CLI_NO_DEV_SERVER_WAIT`
- `TAURI_DEV_SERVER_PORT` -> `TAURI_CLI_PORT`
- `TAURI_PATH_DEPTH` -> `TAURI_CLI_CONFIG_DEPTH`
- `TAURI_FIPS_COMPLIANT` -> `TAURI_BUNDLER_WIX_FIPS_COMPLIANT`
- `TAURI_DEV_WATCHER_IGNORE_FILE` -> `TAURI_CLI_WATCHER_IGNORE_FILENAME`
- `TAURI_TRAY` -> `TAURI_LINUX_AYATANA_APPINDICATOR`
- `TAURI_APPLE_DEVELOPMENT_TEAM` -> `APPLE_DEVELOPMENT_TEAM`
5 changes: 5 additions & 0 deletions .changes/tauri-runtime-wry-env-vars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'major:breaking'
---

Changed `TAURI_AUTOMATION` to `TAURI_WEBVIEW_AUTOMATION`
2 changes: 1 addition & 1 deletion core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2680,7 +2680,7 @@ fn create_webview<T: UserEvent, F: Fn(RawWindow) + Send + 'static>(

let mut web_context = web_context_store.lock().expect("poisoned WebContext store");
let is_first_context = web_context.is_empty();
let automation_enabled = std::env::var("TAURI_AUTOMATION").as_deref() == Ok("true");
let automation_enabled = std::env::var("TAURI_WEBVIEW_AUTOMATION").as_deref() == Ok("true");
let web_context_key = // force a unique WebContext when automation is false;
// the context must be stored on the HashMap because it must outlive the WebView on macOS
if automation_enabled {
Expand Down
14 changes: 7 additions & 7 deletions tooling/bundler/src/bundle/linux/templates/appimage
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -euxo pipefail
export ARCH={{arch}}
APPIMAGE_BUNDLE_XDG_OPEN=${APPIMAGE_BUNDLE_XDG_OPEN-0}
APPIMAGE_BUNDLE_GSTREAMER=${APPIMAGE_BUNDLE_GSTREAMER-0}
TRAY_LIBRARY_PATH=${TRAY_LIBRARY_PATH-0}
TAURI_TRAY_LIBRARY_PATH=${TAURI_TRAY_LIBRARY_PATH-0}

if [ "$ARCH" == "i686" ]; then
linuxdeploy_arch="i386"
Expand All @@ -28,15 +28,15 @@ if [[ "$APPIMAGE_BUNDLE_XDG_OPEN" != "0" ]] && [[ -f "/usr/bin/xdg-open" ]]; the
cp /usr/bin/xdg-open usr/bin
fi

if [[ "$TRAY_LIBRARY_PATH" != "0" ]]; then
echo "Copying appindicator library ${TRAY_LIBRARY_PATH}"
cp ${TRAY_LIBRARY_PATH} usr/lib
if [[ "$TAURI_TRAY_LIBRARY_PATH" != "0" ]]; then
echo "Copying appindicator library ${TAURI_TRAY_LIBRARY_PATH}"
cp ${TAURI_TRAY_LIBRARY_PATH} usr/lib
# It looks like we're practicing good hygiene by adding the ABI version.
# But for compatibility we'll symlink this file to what we did before.
# Specifically this prevents breaking libappindicator-sys v0.7.1 and v0.7.2.
if [[ "$TRAY_LIBRARY_PATH" == *.so.1 ]]; then
readonly soname=$(basename "$TRAY_LIBRARY_PATH")
readonly old_name=$(basename "$TRAY_LIBRARY_PATH" .1)
if [[ "$TAURI_TRAY_LIBRARY_PATH" == *.so.1 ]]; then
readonly soname=$(basename "$TAURI_TRAY_LIBRARY_PATH")
readonly old_name=$(basename "$TAURI_TRAY_LIBRARY_PATH" .1)
echo "Adding compatibility symlink ${old_name} -> ${soname}"
ln -s ${soname} usr/lib/${old_name}
fi
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jsonrpsee-ws-client = { version = "0.16", default-features = false }
thiserror = "1"
sublime_fuzzy = "0.7"
clap_complete = "4"
clap = { version = "4.0", features = [ "derive" ] }
clap = { version = "4.0", features = [ "derive", "env" ] }
anyhow = "1.0"
tauri-bundler = { version = "2.0.0-alpha.8", default-features = false, path = "../bundler" }
colored = "2.0"
Expand Down
28 changes: 15 additions & 13 deletions tooling/cli/ENVIRONMENT_VARIABLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,30 @@ These environment variables are inputs to the CLI which may have an equivalent C

> if both environment variable and CLI flag are used, the CLI flag will have priority.
- `TAURI_PATH_DEPTH` — Number of levels to traverse and find tauri configuration file.
- `TAURI_DEV_SERVER_PORT` — Port to use for the CLI built-in dev server.
- `TAURI_DEV_WATCHER_IGNORE_FILE` — A `.gitignore`-style file to control which files should be watched by the CLI in `dev` command.
- `TAURI_SKIP_DEVSERVER_CHECK` — Skip waiting for the frontend dev server to start before building the tauri application.
- `TAURI_SKIP_UPDATE_CHECK` — Skip checking for a newer CLI version before exiting the CLI process.
- `TAURI_TRAY` — Set this var to `ayatana` to use `libayatana-appindicator` for system tray on Linux or set it `appindicator` to use `libappindicator`.
- For `deb` bundle target, the CLI will add the appropriate package as a dependency, if unset, the CLI will default to `ayatana`.
- For `appimage` bundle target, the CLI will copy the appropriate package to the appimage. if unset, the CLI will make a guess based on what package is installed on the developer system.
- `TAURI_FIPS_COMPLIANT` — Specify WiX `FipsCompliant` option
- `TAURI_PRIVATE_KEY` — Private key used to sign your app bundles
- `TAURI_KEY_PASSWORD` — The private key password, see `TAURI_PRIVATE_KEY`
- `CI` — If set, the CLI will run in CI mode and won't require any user interaction.
- `TAURI_CLI_CONFIG_DEPTH` — Number of levels to traverse and find tauri configuration file.
- `TAURI_CLI_PORT` — Port to use for the CLI built-in dev server.
- `TAURI_CLI_WATCHER_IGNORE_FILENAME` — Name of a `.gitignore`-style file to control which files should be watched by the CLI in `dev` command. The CLI will look for this file name in each directory.
- `TAURI_CLI_NO_DEV_SERVER_WAIT` — Skip waiting for the frontend dev server to start before building the tauri application.
- `TAURI_LINUX_AYATANA_APPINDICATOR` — Set this var to `true` or `1` to force usage of `libayatana-appindicator` for system tray on Linux.
- `TAURI_BUNDLER_WIX_FIPS_COMPLIANT` — Specify the bundler's WiX `FipsCompliant` option.
- `TAURI_SIGNINING_PRIVATE_KEY` — Private key used to sign your app bundles, can be either a string or a path to the file.
- `TAURI_SIGNINING_PRIVATE_KEY_PASSWORD` — The signging private key password, see `TAURI_SIGNINING_PRIVATE_KEY`.
- `APPLE_CERTIFICATE` — Base64 encoded of the `.p12` certificate for code signing. To get this value, run `openssl base64 -in MyCertificate.p12 -out MyCertificate-base64.txt`.
- `APPLE_CERTIFICATE_PASSWORD` — The password you used to export the certificate.
- `APPLE_ID` — The Apple ID used to notarize the application. If this environment variable is provided, `APPLE_PASSWORD` must also be set. Alternatively, `APPLE_API_KEY` and `APPLE_API_ISSUER` can be used to authenticate.
- `APPLE_PASSWORD` — The Apple password used to authenticate for application notarization. Required if `APPLE_ID` is specified. An app-specific password can be used. Alternatively to entering the password in plaintext, it may also be specified using a '@keychain:' or '@env:' prefix followed by a keychain password item name or environment variable name.
- `APPLE_API_KEY` — Alternative to `APPLE_ID` and `APPLE_PASSWORD` for notarization authentication using JWT.
- This option will search the following directories in sequence for a private key file with the name of 'AuthKey_<api_key>.p8': './private_keys', '~/private_keys', '~/.private_keys', and '~/.appstoreconnect/private_keys'. Additionally, you can set environment variable $API_PRIVATE_KEYS_DIR or a user default API_PRIVATE_KEYS_DIR to specify the directory where your AuthKey file is located.
- This option will search the following directories in sequence for a private key file with the name of `AuthKey\_<api_key>.p8`: `./private_keys`, `~/private_keys`, `~/.private_keys`, and `~/.appstoreconnect/private_keys`. Additionally, you can set environment variable `API_PRIVATE_KEYS_DIR` to specify the directory where your AuthKey file is located.
- See [creating API keys](https://developer.apple.com/documentation/appstoreconnectapi/creating_api_keys_for_app_store_connect_api) for more information.
- `API_PRIVATE_KEYS_DIR` — Specify the directory where your AuthKey file is located. See `APPLE_API_KEY`.
- `APPLE_API_ISSUER` — Issuer ID. Required if `APPLE_API_KEY` is specified.
- `APPLE_SIGNING_IDENTITY` — The identity used to code sign. Overwrites `tauri.conf.json > tauri > bundle > macOS > signingIdentity`.
- `APPLE_PROVIDER_SHORT_NAME` — If your Apple ID is connected to multiple teams, you have to specify the provider short name of the team you want to use to notarize your app. Overwrites `tauri.conf.json > tauri > bundle > macOS > providerShortName`.
- `CI` — If set, the CLI will run in CI mode and won't require any user interaction.
- `APPLE_DEVELOPMENT_TEAM` — TODO
- `TAURI_WEBVIEW_AUTOMATION` — Enables webview automation (Linux Only).
- `TAURI_ANDROID_PROJECT_PATH` — Path of the tauri android project, usually will be `<project>/src-tauri/gen/android`.
- `TAURI_IOS_PROJECT_PATH` — Path of the tauri iOS project, usually will be `<project>/src-tauri/gen/ios`.

### Tauri CLI Hook Commands

Expand Down
8 changes: 4 additions & 4 deletions tooling/cli/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ pub fn command(mut options: Options, verbosity: u8) -> Result<()> {
// If updater is active and we bundled it
if config_.tauri.bundle.updater.active && !updater_bundles.is_empty() {
// if no password provided we use an empty string
let password = var_os("TAURI_KEY_PASSWORD")
let password = var_os("TAURI_SIGNINING_PRIVATE_KEY_PASSWORD")
.map(|v| v.to_str().unwrap().to_string())
.or_else(|| if ci { Some("".into()) } else { None });
// get the private key
let secret_key = if let Some(mut private_key) =
var_os("TAURI_PRIVATE_KEY").map(|v| v.to_str().unwrap().to_string())
var_os("TAURI_SIGNINING_PRIVATE_KEY").map(|v| v.to_str().unwrap().to_string())
{
// check if env var points to a file..
let pk_dir = Path::new(&private_key);
Expand All @@ -183,7 +183,7 @@ pub fn command(mut options: Options, verbosity: u8) -> Result<()> {
}
updater_secret_key(private_key, password)
} else {
Err(anyhow::anyhow!("A public key has been found, but no private key. Make sure to set `TAURI_PRIVATE_KEY` environment variable."))
Err(anyhow::anyhow!("A public key has been found, but no private key. Make sure to set `TAURI_SIGNINING_PRIVATE_KEY` environment variable."))
}?;

let pubkey =
Expand All @@ -201,7 +201,7 @@ pub fn command(mut options: Options, verbosity: u8) -> Result<()> {
let (signature_path, signature) = sign_file(&secret_key, path)?;
if signature.keynum() != public_key.keynum() {
return Err(anyhow::anyhow!(
"The updater secret key from `TAURI_PRIVATE_KEY` does not match the public key defined in `tauri.conf.json > tauri > updater > pubkey`."
"The updater secret key from `TAURI_SIGNINING_PRIVATE_KEY` does not match the public key defined in `tauri.conf.json > tauri > updater > pubkey`."
));
}
signed_paths.append(&mut vec![signature_path]);
Expand Down
52 changes: 16 additions & 36 deletions tooling/cli/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ static KILL_BEFORE_DEV_FLAG: OnceCell<AtomicBool> = OnceCell::new();
#[cfg(unix)]
const KILL_CHILDREN_SCRIPT: &[u8] = include_bytes!("../scripts/kill-children.sh");

pub const TAURI_DEV_WATCHER_GITIGNORE: &[u8] = include_bytes!("../tauri-dev-watcher.gitignore");
pub const TAURI_CLI_BUILTIN_WATCHER_IGNORE_FILE: &[u8] =
include_bytes!("../tauri-dev-watcher.gitignore");

#[derive(Debug, Clone, Parser)]
#[clap(about = "Tauri dev", trailing_var_arg(true))]
Expand All @@ -61,19 +62,22 @@ pub struct Options {
pub release_mode: bool,
/// Command line arguments passed to the runner. Arguments after `--` are passed to the application.
pub args: Vec<String>,
/// Disable the file watcher
/// Skip waiting for the frontend dev server to start before building the tauri application.
#[clap(long, env = "TAURI_CLI_NO_DEV_SERVER_WAIT")]
pub no_dev_server_wait: bool,
/// Disable the file watcher.
#[clap(long)]
pub no_watch: bool,
/// Disable the dev server for static files.
#[clap(long)]
pub no_dev_server: bool,
/// Specify port for the dev server for static files. Defaults to 1430
/// Can also be set using `TAURI_DEV_SERVER_PORT` env var.
#[clap(long)]
pub port: Option<u16>,
/// Force prompting for an IP to use to connect to the dev server on mobile.
#[clap(long)]
pub force_ip_prompt: bool,

/// Disable the built-in dev server for static files.
#[clap(long)]
pub no_dev_server: bool,
/// Specify port for the built-in dev server for static files. Defaults to 1430.
#[clap(long, env = "TAURI_CLI_PORT")]
pub port: Option<u16>,
}

pub fn command(options: Options) -> Result<()> {
Expand Down Expand Up @@ -318,24 +322,20 @@ pub fn setup(target: Target, options: &mut Options, mobile: bool) -> Result<AppI
let server_url = format!("http://{server_url}");
dev_path = AppUrl::Url(WindowUrl::External(server_url.parse().unwrap()));

// TODO: in v2, use an env var to pass the url to the app context
// or better separate the config passed from the cli internally and
// config passed by the user in `--config` into to separate env vars
// and the context merges, the user first, then the internal cli config
if let Some(c) = &options.config {
let mut c: tauri_utils::config::Config = serde_json::from_str(c)?;
c.build.dev_path = dev_path.clone();
options.config = Some(serde_json::to_string(&c).unwrap());
} else {
options.config = Some(format!(r#"{{ "build": {{ "devPath": "{server_url}" }} }}"#))
}

reload_config(options.config.as_deref())?;
}
}

reload_config(options.config.as_deref())?;
}

if std::env::var_os("TAURI_SKIP_DEVSERVER_CHECK") != Some("true".into()) {
if !options.no_dev_server_wait {
if let AppUrl::Url(WindowUrl::External(dev_server_url)) = dev_path {
let host = dev_server_url
.host()
Expand Down Expand Up @@ -423,30 +423,10 @@ pub fn on_app_exit(code: Option<i32>, reason: ExitReason, exit_on_panic: bool, n
&& (exit_on_panic || matches!(reason, ExitReason::NormalExit)))
{
kill_before_dev_process();
#[cfg(not(debug_assertions))]
let _ = check_for_updates();
exit(code.unwrap_or(0));
}
}

#[cfg(not(debug_assertions))]
fn check_for_updates() -> Result<()> {
if std::env::var_os("TAURI_SKIP_UPDATE_CHECK") != Some("true".into()) {
let current_version = crate::info::cli_current_version()?;
let current = semver::Version::parse(&current_version)?;

let upstream_version = crate::info::cli_upstream_version()?;
let upstream = semver::Version::parse(&upstream_version)?;
if current < upstream {
println!(
"🚀 A new version of Tauri CLI is available! [{}]",
upstream.to_string()
);
};
}
Ok(())
}

pub fn kill_before_dev_process() {
if let Some(child) = BEFORE_DEV.get() {
let child = child.lock().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions tooling/cli/src/helpers/app_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ fn lookup<F: Fn(&PathBuf) -> bool>(dir: &Path, checker: F) -> Option<PathBuf> {
.require_git(false)
.ignore(false)
.max_depth(Some(
std::env::var("TAURI_PATH_DEPTH")
std::env::var("TAURI_CLI_CONFIG_DEPTH")
.map(|d| {
d.parse()
.expect("`TAURI_PATH_DEPTH` environment variable must be a positive integer")
.expect("`TAURI_CLI_CONFIG_DEPTH` environment variable must be a positive integer")
})
.unwrap_or(3),
))
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/src/helpers/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn wix_settings(config: WixConfig) -> tauri_bundler::WixSettings {
enable_elevated_update_task: config.enable_elevated_update_task,
banner_path: config.banner_path,
dialog_image_path: config.dialog_image_path,
fips_compliant: var_os("TAURI_FIPS_COMPLIANT").map_or(false, |v| v == "true"),
fips_compliant: var_os("TAURI_BUNDLER_WIX_FIPS_COMPLIANT").map_or(false, |v| v == "true"),
}
}

Expand Down
9 changes: 2 additions & 7 deletions tooling/cli/src/helpers/web_dev_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,8 @@ pub fn start_dev_server<P: AsRef<Path>>(

let mut auto_port = false;
let mut port = port.unwrap_or_else(|| {
std::env::var("TAURI_DEV_SERVER_PORT")
.unwrap_or_else(|_| {
auto_port = true;
"1430".to_string()
})
.parse()
.unwrap()
auto_port = true;
1430
});

let (server, server_url) = loop {
Expand Down
19 changes: 11 additions & 8 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,14 @@ fn build_ignore_matcher(dir: &Path) -> IgnoreMatcher {

ignore_builder.add(path);

if let Ok(ignore_file) = std::env::var("TAURI_DEV_WATCHER_IGNORE_FILE") {
if let Ok(ignore_file) = std::env::var("TAURI_CLI_WATCHER_IGNORE_FILENAME") {
ignore_builder.add(dir.join(ignore_file));
}

for line in crate::dev::TAURI_DEV_WATCHER_GITIGNORE.lines().flatten() {
for line in crate::dev::TAURI_CLI_BUILTIN_WATCHER_IGNORE_FILE
.lines()
.flatten()
{
let _ = ignore_builder.add_line(None, &line);
}

Expand All @@ -328,14 +331,14 @@ fn lookup<F: FnMut(FileType, PathBuf)>(dir: &Path, mut f: F) {
default_gitignore.push(".gitignore");
if !default_gitignore.exists() {
if let Ok(mut file) = std::fs::File::create(default_gitignore.clone()) {
let _ = file.write_all(crate::dev::TAURI_DEV_WATCHER_GITIGNORE);
let _ = file.write_all(crate::dev::TAURI_CLI_BUILTIN_WATCHER_IGNORE_FILE);
}
}

let mut builder = ignore::WalkBuilder::new(dir);
builder.add_custom_ignore_filename(".taurignore");
let _ = builder.add_ignore(default_gitignore);
if let Ok(ignore_file) = std::env::var("TAURI_DEV_WATCHER_IGNORE_FILE") {
if let Ok(ignore_file) = std::env::var("TAURI_CLI_WATCHER_IGNORE_FILENAME") {
builder.add_ignore(ignore_file);
}
builder.require_git(false).ignore(false).max_depth(Some(1));
Expand Down Expand Up @@ -1069,9 +1072,9 @@ fn tauri_config_to_bundle_settings(
if enabled_features.contains(&"tray-icon".into())
|| enabled_features.contains(&"tauri/tray-icon".into())
{
let (tray_kind, path) = std::env::var("TAURI_TRAY")
.map(|kind| {
if kind == "ayatana" {
let (tray_kind, path) = std::env::var("TAURI_LINUX_AYATANA_APPINDICATOR")
.map(|ayatana| {
if ayatana == "true" || ayatana == "1" {
(
pkgconfig_utils::TrayKind::Ayatana,
format!(
Expand Down Expand Up @@ -1101,7 +1104,7 @@ fn tauri_config_to_bundle_settings(
}
}

std::env::set_var("TRAY_LIBRARY_PATH", path);
std::env::set_var("TAURI_TRAY_LIBRARY_PATH", path);
}

// provides `libwebkit2gtk-4.1.so.37` and all `4.0` versions have the -37 package name
Expand Down
Loading

0 comments on commit 72fb8cb

Please sign in to comment.