Skip to content

Commit

Permalink
fix(examples): build error (#1354)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
  • Loading branch information
nklayman and lucasfernog committed Mar 13, 2021
1 parent 1086b3b commit 4c9d419
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 33 deletions.
6 changes: 3 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Tauri.js is a CLI tool that houses the `init`, `info`, `icon`, and `deps` comman
- `lint` runs ESLint to catch linting errors
- `format` formats code with Prettier to match the style guide

To test your changes, we recommend using the API example app, located in `[Tauri repo root]/tauri/examples/api`. Run `yarn install` to install deps, and then `yarn tauri [COMMAND]` to run a command using your local Tauri.js copy. You will need to rebuild Tauri.js after every change by running `yarn build` in the Tauri.js directory.
To test your changes, we recommend using the helloworld example app, located in `[Tauri repo root]/examples/helloworld`. Run `yarn tauri [COMMAND]` to run a command using your local Tauri.js copy. You will need to rebuild Tauri.js after every change by running `yarn build` in the Tauri.js directory.

If you want to use your local copy of Tauri.js in another app, we recommend using [Yarn link](https://classic.yarnpkg.com/en/docs/cli/link/). First, make sure you have don't have Tauri.js installed globally by running `npm uninstall -g tauri && yarn global remove tauri`. Then, run `yarn link` in the Tauri.js directory (note that the setup script will do this for you, so you can skip this step if you ran that). Now, you can just run `tauri [COMMAND]` anywhere, and your local copy will be used.

Expand All @@ -79,11 +79,11 @@ The code for the bundler is located in `[Tauri repo root]/cli/tauri-bundler`, an

### Developing Tauri Core and Related Components (Rust API, Macros, and Utils)

The code for Tauri Core is located in `[Tauri repo root]/tauri`, and the Rust API, Macros, and Utils are in `[Tauri repo root]/tauri-(api/macros/utils)`. The easiest way to test your changes is to use the `[Tauri repo root]/tauri/examples/helloworld` app. It automatically rebuilds and uses your local copy of the Tauri core packages. Just run `yarn tauri build` or `yarn tauri dev` in the helloworld app directory after making changes to test them out. To use your local changes in another project, edit its `src-tauri/Cargo.toml` file so that the `tauri` key looks like `tauri = { path = "PATH", features = [ "api-all", "cli" ] }`, where `PATH` is the relative path to `[Tauri repo root]/tauri`. Then, your local copy of the Tauri core packages will be rebuilt and used whenever you build that project.
The code for Tauri Core is located in `[Tauri repo root]/tauri`, and the Rust API, Macros, and Utils are in `[Tauri repo root]/tauri-(api/macros/utils)`. The easiest way to test your changes is to use the `[Tauri repo root]/examples/helloworld` app. It automatically rebuilds and uses your local copy of the Tauri core packages. Just run `yarn tauri build` or `yarn tauri dev` in the helloworld app directory after making changes to test them out. To use your local changes in another project, edit its `src-tauri/Cargo.toml` file so that the `tauri` key looks like `tauri = { path = "PATH", features = [ "api-all", "cli" ] }`, where `PATH` is the relative path to `[Tauri repo root]/tauri`. Then, your local copy of the Tauri core packages will be rebuilt and used whenever you build that project.

### Developing the JS API

The JS API provides bindings between the developer's JS in the Webview and the builtin Tauri APIs, written in Rust. Its code is located in `[Tauri repo root]/api`. After making changes to the code, run `yarn build` to build it. To test your changes, we recommend using the API example app, located in `[Tauri repo root]/tauri/examples/api`. It will automatically use your local copy of the JS API and provides a helpful UI to test the various commands.
The JS API provides bindings between the developer's JS in the Webview and the builtin Tauri APIs, written in Rust. Its code is located in `[Tauri repo root]/api`. After making changes to the code, run `yarn build` to build it. To test your changes, we recommend using the API example app, located in `[Tauri repo root]/examples/api`. It will automatically use your local copy of the JS API and provides a helpful UI to test the various commands.

## Financial Contribution

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/core-lint-fmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ on:
pull_request:
paths:
- '.github/workflows/core-lint-fmt.yml'
- 'core/**'
- 'examples/**'
- 'tauri/**'
- 'tauri-utils/**'
- 'tauri-api/**'
- 'tauri-macros/**'
- 'tauri-updater/**'
- 'cli/core/**'

jobs:
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/test-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ on:
pull_request:
paths:
- '.github/workflows/test-core.yml'
- 'cli/**'
- 'core/**'
- 'examples/**'
- 'tauri/**'
- 'tauri-api/**'
- 'tauri-utils/**'
- 'tauri-api/**'
- 'tauri-macros/**'
- 'tauri-updater/**'
- 'cli/**'

env:
RUST_BACKTRACE: 1
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/udeps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ on:
pull_request:
paths:
- '.github/workflows/udeps.yml'
- 'cli/tauri-bundler/**'
- 'cli/core/**'
- 'core/**'
- 'tauri/**'
- 'tauri-api/**'
- 'tauri-utils/**'
- 'tauri-api/**'
- 'tauri-macros/**'
- 'tauri-updater/**'
- 'cli/tauri-bundler/**'
- 'cli/core/**'

jobs:
udeps:
Expand Down
6 changes: 3 additions & 3 deletions cli/tauri.js/templates/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
)]

fn main() {
let context = tauri::generate_tauri_context!();

tauri::AppBuilder::default().build(context).run();
tauri::AppBuilder::default()
.build(tauri::generate_context!())
.run();
}
4 changes: 1 addition & 3 deletions cli/tauri.js/test/jest/fixtures/app/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use tauri::ApplicationDispatcherExt;

fn main() {
let context = tauri::generate_tauri_context!();

tauri::AppBuilder::default()
.setup(|webview_manager| async move {
let mut webview_manager_ = webview_manager.clone();
Expand All @@ -23,6 +21,6 @@ fn main() {
webview_manager.close().unwrap();
}
})
.build(context)
.build(tauri::generate_context!())
.run();
}
4 changes: 1 addition & 3 deletions examples/api/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ struct Reply {
}

fn main() {
let context = tauri::generate_tauri_context!();

tauri::AppBuilder::default()
.setup(|webview_manager| async move {
let dispatcher = webview_manager.current_webview().unwrap();
Expand All @@ -34,6 +32,6 @@ fn main() {
cmd::log_operation,
cmd::perform_request
])
.build(context)
.build(tauri::generate_context!())
.run();
}
2 changes: 1 addition & 1 deletion examples/helloworld/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"name": "hello-world",
"version": "1.0.0",
"scripts": {
"tauri": "node ../../../cli/tauri.js/bin/tauri"
"tauri": "node ../../cli/tauri.js/bin/tauri"
}
}
1 change: 0 additions & 1 deletion examples/helloworld/src-tauri/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
fn main() {
tauri_build::CodegenContext::default().build();
tauri_build::build();
}
4 changes: 1 addition & 3 deletions examples/helloworld/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ fn my_custom_command(argument: String) {
}

fn main() {
let context = tauri::generate_tauri_context!();

tauri::AppBuilder::default()
.invoke_handler(tauri::generate_handler![my_custom_command])
.build(context)
.build(tauri::generate_context!())
.run();
}
2 changes: 1 addition & 1 deletion examples/multiwindow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "node ../../../cli/tauri.js/bin/tauri build"
"tauri": "node ../../cli/tauri.js/bin/tauri"
},
"private": true
}
2 changes: 1 addition & 1 deletion examples/multiwindow/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "An example Tauri Multi-Window Application"
edition = "2018"

[build-dependencies]
tauri-build = { path = "../../../core/tauri-build", features = ["codegen"] }
tauri-build = { path = "../../../core/tauri-build" }

[dependencies]
tauri = { path = "../../../tauri", features =["api-all"]}
Expand Down
1 change: 0 additions & 1 deletion examples/multiwindow/src-tauri/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
fn main() {
tauri_build::CodegenContext::default().build();
tauri_build::build();
}
4 changes: 1 addition & 3 deletions examples/multiwindow/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use tauri::WebviewBuilderExt;

fn main() {
let context = tauri::tauri_build_context!();

tauri::AppBuilder::default()
.setup(|webview_manager| async move {
if webview_manager.current_window_label() == "Main" {
Expand All @@ -26,6 +24,6 @@ fn main() {
Ok(builder)
})
.unwrap()
.build(context)
.build(tauri::generate_context!())
.run();
}
2 changes: 1 addition & 1 deletion tauri-macros/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ macro_rules! parse_config_path {
}
}

pub(crate) fn generate_tauri_context(path: PathBuf) -> TokenStream {
pub(crate) fn generate_context(path: PathBuf) -> TokenStream {
let context = get_config(&path)
.map_err(|e| e.to_string())
.map(|(config, config_parent)| ContextData {
Expand Down
4 changes: 2 additions & 2 deletions tauri-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub fn generate_handler(item: TokenStream) -> TokenStream {
///
/// todo: link the [`AsTauriContext`] docs
#[proc_macro]
pub fn generate_tauri_context(item: TokenStream) -> TokenStream {
pub fn generate_context(item: TokenStream) -> TokenStream {
// this macro is exported from the context module
let path = parse_config_path!(item);
context::generate_tauri_context(path).into()
context::generate_context(path).into()
}
4 changes: 2 additions & 2 deletions tauri/src/app/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ async fn on_message<A: ApplicationExt + 'static>(

#[cfg(test)]
mod test {
use crate::{generate_tauri_context, Context};
use crate::{generate_context, Context};

#[test]
fn check_get_url() {
let context = generate_tauri_context!("test/fixture/src-tauri/tauri.conf.json");
let context = generate_context!("test/fixture/src-tauri/tauri.conf.json");
let context = Context::new(context);
let res = super::get_url(&context);
#[cfg(custom_protocol)]
Expand Down

0 comments on commit 4c9d419

Please sign in to comment.