Skip to content

Commit ed58195

Browse files
authored
fix(tauri-build): use ::tauri as root for the CodegenContext (#4894)
1 parent f957cbb commit ed58195

6 files changed

Lines changed: 16 additions & 5 deletions

File tree

.changes/fix-build-codegen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-build": patch
3+
---
4+
5+
Fix root of codegen output when using the `CodegenContext` API.

core/tauri-build/src/codegen/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ impl CodegenContext {
5252
///
5353
/// **Note:** This path should be relative to the `OUT_DIR`.
5454
///
55-
/// Don't set this if you are using [`tauri::include_codegen_context!`] as that helper macro
55+
/// Don't set this if you are using [`tauri::tauri_build_context!`] as that helper macro
5656
/// expects the default value. This option can be useful if you are not using the helper and
5757
/// instead using [`std::include!`] on the generated code yourself.
5858
///
5959
/// Defaults to `tauri-build-context.rs`.
6060
///
61-
/// [`tauri::include_codegen_context!`]: https://docs.rs/tauri/0.12/tauri/macro.include_codegen_context.html
61+
/// [`tauri::tauri_build_context!`]: https://docs.rs/tauri/latest/tauri/macro.tauri_build_context.html
6262
#[must_use]
6363
pub fn out_file(mut self, filename: PathBuf) -> Self {
6464
self.out_file = filename;
@@ -98,7 +98,7 @@ impl CodegenContext {
9898
config_parent,
9999
// it's very hard to have a build script for unit tests, so assume this is always called from
100100
// outside the tauri crate, making the ::tauri root valid.
101-
root: quote::quote!(::tauri::Context),
101+
root: quote::quote!(::tauri),
102102
})?;
103103

104104
// get the full output file path

examples/api/src-tauri/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/api/src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ rust-version = "1.57"
77
license = "Apache-2.0 OR MIT"
88

99
[build-dependencies]
10-
tauri-build = { path = "../../../core/tauri-build", features = ["isolation"] }
10+
tauri-build = { path = "../../../core/tauri-build", features = ["isolation", "codegen"] }
1111

1212
[dependencies]
1313
serde_json = "1.0"

examples/api/src-tauri/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@
33
// SPDX-License-Identifier: MIT
44

55
fn main() {
6+
let mut codegen = tauri_build::CodegenContext::new();
7+
if !cfg!(feature = "custom-protocol") {
8+
codegen = codegen.dev();
9+
}
10+
codegen.build();
611
tauri_build::build()
712
}

examples/api/src-tauri/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn main() {
199199
cmd::log_operation,
200200
cmd::perform_request,
201201
])
202-
.build(tauri::generate_context!())
202+
.build(tauri::tauri_build_context!())
203203
.expect("error while building tauri application");
204204

205205
#[cfg(target_os = "macos")]

0 commit comments

Comments
 (0)