Skip to content

Commit

Permalink
fix(cli): use npm run tauri -- foo for correctly passing args to ta…
Browse files Browse the repository at this point in the history
…uri (#6448)

* fix(cli): use `npm run tauri -- foo` for correctly pass args to tauri

* fix xcode-script current dir, GCC_PREPROCESSOR_DEFINITIONS optional

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
  • Loading branch information
meowtec and lucasfernog authored Mar 16, 2023
1 parent 4d09074 commit 1b343bd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changes/npm-pass-args.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'cli.rs': 'patch'
"cli.js": patch
---

Correctly pass arguments from `npm run` to `tauri`.
1 change: 1 addition & 0 deletions tooling/cli/src/mobile/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ pub fn exec(
// remove script path, we'll use `npm_lifecycle_event` instead
build_args.remove(0);
}
build_args.insert(0, "--".into());
build_args.insert(0, var("npm_lifecycle_event").unwrap());
build_args.insert(0, "run".into());
}
Expand Down
24 changes: 13 additions & 11 deletions tooling/cli/src/mobile/ios/xcode_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
use clap::Parser;
use tauri_mobile::{apple::target::Target, opts::Profile, util};

use std::{collections::HashMap, ffi::OsStr, path::PathBuf};
use std::{collections::HashMap, env::var_os, ffi::OsStr, path::PathBuf};

#[derive(Debug, Parser)]
pub struct Options {
Expand Down Expand Up @@ -55,16 +55,18 @@ pub fn command(options: Options) -> Result<()> {
}
}

// `xcode-script` is ran from the `gen/apple` folder.
std::env::set_current_dir(
std::env::current_dir()
.unwrap()
.parent()
.unwrap()
.parent()
.unwrap(),
)
.unwrap();
// `xcode-script` is ran from the `gen/apple` folder when not using NPM.
if var_os("npm_lifecycle_event").is_none() {
std::env::set_current_dir(
std::env::current_dir()
.unwrap()
.parent()
.unwrap()
.parent()
.unwrap(),
)
.unwrap();
}

let profile = profile_from_configuration(&options.configuration);
let macos = macos_from_platform(&options.platform);
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/templates/mobile/ios/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ targets:
discoveredDependencyFile: {{this.discovered-dependency-file}}{{/if}}
{{~/each}}

- script: {{ tauri-binary }} {{ tauri-binary-args-str }} -v --platform ${PLATFORM_DISPLAY_NAME:?} --sdk-root ${SDKROOT:?} --framework-search-paths "${FRAMEWORK_SEARCH_PATHS:?}" --header-search-paths "${HEADER_SEARCH_PATHS:?}" --gcc-preprocessor-definitions "${GCC_PREPROCESSOR_DEFINITIONS:?}" --configuration ${CONFIGURATION:?} ${FORCE_COLOR} ${ARCHS:?}
- script: {{ tauri-binary }} {{ tauri-binary-args-str }} -v --platform ${PLATFORM_DISPLAY_NAME:?} --sdk-root ${SDKROOT:?} --framework-search-paths "${FRAMEWORK_SEARCH_PATHS:?}" --header-search-paths "${HEADER_SEARCH_PATHS:?}" --gcc-preprocessor-definitions "${GCC_PREPROCESSOR_DEFINITIONS:-}" --configuration ${CONFIGURATION:?} ${FORCE_COLOR} ${ARCHS:?}
name: Build Rust Code
basedOnDependencyAnalysis: false
outputFiles:
Expand Down

0 comments on commit 1b343bd

Please sign in to comment.