diff --git a/.changes/fix-build-codegen.md b/.changes/fix-build-codegen.md new file mode 100644 index 000000000..2a5f62cb9 --- /dev/null +++ b/.changes/fix-build-codegen.md @@ -0,0 +1,5 @@ +--- +"tauri-build": patch +--- + +Fix root of codegen output when using the `CodegenContext` API. diff --git a/core/tauri-build/src/codegen/context.rs b/core/tauri-build/src/codegen/context.rs index 29356b098..a8c26df4b 100644 --- a/core/tauri-build/src/codegen/context.rs +++ b/core/tauri-build/src/codegen/context.rs @@ -52,13 +52,13 @@ impl CodegenContext { /// /// **Note:** This path should be relative to the `OUT_DIR`. /// - /// Don't set this if you are using [`tauri::include_codegen_context!`] as that helper macro + /// Don't set this if you are using [`tauri::tauri_build_context!`] as that helper macro /// expects the default value. This option can be useful if you are not using the helper and /// instead using [`std::include!`] on the generated code yourself. /// /// Defaults to `tauri-build-context.rs`. /// - /// [`tauri::include_codegen_context!`]: https://docs.rs/tauri/0.12/tauri/macro.include_codegen_context.html + /// [`tauri::tauri_build_context!`]: https://docs.rs/tauri/latest/tauri/macro.tauri_build_context.html #[must_use] pub fn out_file(mut self, filename: PathBuf) -> Self { self.out_file = filename; @@ -98,7 +98,7 @@ impl CodegenContext { config_parent, // it's very hard to have a build script for unit tests, so assume this is always called from // outside the tauri crate, making the ::tauri root valid. - root: quote::quote!(::tauri::Context), + root: quote::quote!(::tauri), })?; // get the full output file path diff --git a/examples/api/src-tauri/Cargo.lock b/examples/api/src-tauri/Cargo.lock index f60bd39bd..dee9803f6 100644 --- a/examples/api/src-tauri/Cargo.lock +++ b/examples/api/src-tauri/Cargo.lock @@ -3165,6 +3165,7 @@ dependencies = [ "cargo_toml", "heck 0.4.0", "json-patch", + "quote", "semver 1.0.12", "serde_json", "tauri-codegen", diff --git a/examples/api/src-tauri/Cargo.toml b/examples/api/src-tauri/Cargo.toml index cd75333d5..07bc72043 100644 --- a/examples/api/src-tauri/Cargo.toml +++ b/examples/api/src-tauri/Cargo.toml @@ -7,7 +7,7 @@ rust-version = "1.57" license = "Apache-2.0 OR MIT" [build-dependencies] -tauri-build = { path = "../../../core/tauri-build", features = ["isolation"] } +tauri-build = { path = "../../../core/tauri-build", features = ["isolation", "codegen"] } [dependencies] serde_json = "1.0" diff --git a/examples/api/src-tauri/build.rs b/examples/api/src-tauri/build.rs index 71557e5b9..2a0f54065 100644 --- a/examples/api/src-tauri/build.rs +++ b/examples/api/src-tauri/build.rs @@ -3,5 +3,10 @@ // SPDX-License-Identifier: MIT fn main() { + let mut codegen = tauri_build::CodegenContext::new(); + if !cfg!(feature = "custom-protocol") { + codegen = codegen.dev(); + } + codegen.build(); tauri_build::build() } diff --git a/examples/api/src-tauri/src/main.rs b/examples/api/src-tauri/src/main.rs index fd181f628..44f2e8ef2 100644 --- a/examples/api/src-tauri/src/main.rs +++ b/examples/api/src-tauri/src/main.rs @@ -199,7 +199,7 @@ fn main() { cmd::log_operation, cmd::perform_request, ]) - .build(tauri::generate_context!()) + .build(tauri::tauri_build_context!()) .expect("error while building tauri application"); #[cfg(target_os = "macos")]