Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error when adding CrabNebula DevTools as per documentation #3152

Closed
caipeter888 opened this issue Feb 3, 2025 · 4 comments · Fixed by #3154
Closed

Compilation error when adding CrabNebula DevTools as per documentation #3152

caipeter888 opened this issue Feb 3, 2025 · 4 comments · Fixed by #3154
Labels
bug Does it fix inaccurate content or fix a bug? good first issue Is it good for beginners to take up?

Comments

@caipeter888
Copy link

Description:

Following the instructions at CrabNebula DevTools, I encountered a compilation error when integrating the devtools plugin.

Reproduction:

Using the code snippet provided in the documentation:

fn main() {
    #[cfg(debug_assertions)]
    let devtools = tauri_plugin_devtools::init(); // initialize the plugin as early as possible

    let mut builder = tauri::Builder::default();

    #[cfg(debug_assertions)]
    builder = builder.plugin(devtools); // then register it with Tauri

    builder
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

I receive the following error:

error[E0658]: attributes on expressions are experimental    
 --> src\main.rs:7:5
  |
7 |     #[cfg(debug_assertions)]
  |     ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information

For more information about this error, try `rustc --explain E0658`.
error: could not compile `tauri-app` (bin "tauri-app") due to 1 previous error

Workaround:

I found that modifying the code by wrapping the affected assignment in a block allows the code to compile successfully. The updated code is:

fn main() {
    #[cfg(debug_assertions)]
    let devtools = tauri_plugin_devtools::init(); // initialize the plugin as early as possible

    let mut builder = tauri::Builder::default();

    #[cfg(debug_assertions)]
    {
        builder = builder.plugin(devtools); // then register it with Tauri
    }

    builder
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

After this change, the application builds and runs correctly, with the output indicating that Tauri Devtools v2.0.0 is running locally.

Full tauri info output:

$ tauri info

[✔] Environment
    - OS: Windows 10.0.26100 x86_64 (X64)
    ✔ WebView2: 132.0.2957.140
    ✔ MSVC: Visual Studio 生成工具 2022
    ✔ rustc: 1.84.1 (e71f9a9a9 2025-01-27)
    ✔ cargo: 1.84.1 (66221abde 2024-11-19)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 23.7.0
    - pnpm: 10.1.0
    - yarn: 1.22.22
    - npm: 10.8.0
    - bun: 1.2.2

[-] Packages
    - tauri 🦀: 2.2.5
    - tauri-build 🦀: 2.0.5
    - wry 🦀: 0.48.1
    - tao 🦀: 0.31.1
    - @tauri-apps/api : 2.2.0
    - @tauri-apps/cli : 2.2.7

[-] Plugins
    - tauri-plugin-opener 🦀: 2.2.5
    - @tauri-apps/plugin-opener : 2.2.5

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: Vue.js
    - bundler: Vite
@FabianLars FabianLars added good first issue Is it good for beginners to take up? bug Does it fix inaccurate content or fix a bug? labels Feb 3, 2025
@caipeter888
Copy link
Author

caipeter888 commented Feb 3, 2025

Although wrapping the affected assignment in a block allows the code to compile successfully to solve the problem, I don't understand why this error appears.
I would like to thank someone to explain this.

@FabianLars
Copy link
Member

There's not much to explain to be honest. What our docs show is simply not valid Rust syntax (at the moment).

@vasfvitor
Copy link
Contributor

@caipeter888 thanks for reporting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Does it fix inaccurate content or fix a bug? good first issue Is it good for beginners to take up?
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants