Skip to content

feat(macros): add support for rename command macro in tauri-macros #14173#14473

Merged
lucasfernog merged 18 commits into
tauri-apps:devfrom
Tunglies:feat-alias-command
Apr 30, 2026
Merged

feat(macros): add support for rename command macro in tauri-macros #14173#14473
lucasfernog merged 18 commits into
tauri-apps:devfrom
Tunglies:feat-alias-command

Conversation

@Tunglies

Copy link
Copy Markdown
Contributor

Related issues: #14173


Preview

image

IDE & Rust Analyzer

image image image

Test code:

mod me {
    #[tauri::command(alias = "greet_from_me")]
    pub fn hello(name: &str) -> String {
        format!("Hello, {}! Me hello from Rust!", name)
    }
}

mod you {
    #[tauri::command(alias = "greet_from_you")]
    pub fn hello(name: &str) -> String {
        format!("Hi, {}! You hello from Rust!", name)
    }
}

#[tauri::command(alias = "salute")]
fn hello(name: &str) -> String {
    format!("Hello, {}! You've been greeted from Rust!", name)
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![hello, me::hello, you::hello])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
import { invoke } from "@tauri-apps/api/core";
import { useState } from "react";
import "./App.css";
import reactLogo from "./assets/react.svg";

function App() {
  const [greetMsg, setGreetMsg] = useState("");
  const [name, setName] = useState("");

  async function handleGreetAll() {
    const [salute, fromMe, fromYou] = await Promise.all([
      invoke<string>("salute", { name }),
      invoke<string>("greet_from_me", { name }),
      invoke<string>("greet_from_you", { name }),
    ]);
    setGreetMsg([salute, fromMe, fromYou].join("\n"));
  }

  return (
    <main className="container">
      <h1>Welcome to Tauri + React</h1>

      <div className="row">
        <a href="https://vite.dev" target="_blank">
          <img src="/vite.svg" className="logo vite" alt="Vite logo" />
        </a>
        <a href="https://tauri.app" target="_blank">
          <img src="/tauri.svg" className="logo tauri" alt="Tauri logo" />
        </a>
        <a href="https://react.dev" target="_blank">
          <img src={reactLogo} className="logo react" alt="React logo" />
        </a>
      </div>
      <p>Click on the Tauri, Vite, and React logos to learn more.</p>

      <form
        className="row"
        onSubmit={(e) => {
          e.preventDefault();
          handleGreetAll();
        }}
      >
        <input
          id="greet-input"
          onChange={(e) => setName(e.currentTarget.value)}
          placeholder="Enter a name..."
        />
        <button type="submit">Greet</button>
      </form>
      <pre>{greetMsg}</pre>
    </main>
  );
}

export default App;

@Tunglies
Tunglies requested a review from a team as a code owner November 16, 2025 05:26
@FabianLars FabianLars added this to the 2.10 milestone Nov 16, 2025
@Legend-Master

Copy link
Copy Markdown
Contributor

Didn't look much into this yet, but I think if the idea is to rename the command, not having both command names valid, we should call it rename similar to #[serde(rename = "name")]

@github-actions

github-actions Bot commented Nov 19, 2025

Copy link
Copy Markdown
Contributor

Package Changes Through 6d8d05b

There are 12 changes which include tauri with minor, @tauri-apps/api with minor, tauri-macros with minor, tauri-build with minor, tauri-macos-sign with patch, tauri-bundler with minor, @tauri-apps/cli with minor, tauri-cli with minor, tauri-runtime with minor, tauri-runtime-wry with minor, tauri-utils with minor, tauri-plugin with minor

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
@tauri-apps/api 2.10.1 2.11.0
tauri-utils 2.8.3 2.9.0
tauri-macos-sign 2.3.3 2.3.4
tauri-bundler 2.8.1 2.9.0
tauri-runtime 2.10.1 2.11.0
tauri-runtime-wry 2.10.1 2.11.0
tauri-codegen 2.5.5 2.5.6
tauri-macros 2.5.5 2.6.0
tauri-plugin 2.5.4 2.6.0
tauri-build 2.5.6 2.6.0
tauri 2.10.3 2.11.0
@tauri-apps/cli 2.10.1 2.11.0
tauri-cli 2.10.1 2.11.0

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@Tunglies

Tunglies commented Nov 26, 2025

Copy link
Copy Markdown
Contributor Author

Didn't look much into this yet, but I think if the idea is to rename the command, not having both command names valid, we should call it rename similar to #[serde(rename = "name")]

I initially thought of using rename with #[serde(rename = "name")], but ended up keeping alias for functionality first and reference the issue. See if any review ideals I can go further.

@Tunglies Tunglies changed the title feat(macros): add support for alias command macro in tauri-macros #14173 feat(macros): add support for rename command macro in tauri-macros #14173 Dec 1, 2025
@Tunglies

Tunglies commented Dec 1, 2025

Copy link
Copy Markdown
Contributor Author

Didn't look much into this yet, but I think if the idea is to rename the command, not having both command names valid, we should call it rename similar to #[serde(rename = "name")]

It should be clearer now, changed to #[tauri::command(rename = "name")] . Since the new serde method exposed to user, might conflect with #serde(rename_all = "snake_case"), but the priority of rename_all is higher. We might need document on this behavior.

@lucasfernog

Copy link
Copy Markdown
Member

pushed some fixes for commands defined in a separate module (the commands example is a good way to test this). Unfortunately we need to always export the macro, and preserve the condition of unique command function names :/

Comment thread examples/commands/main.rs
Comment on lines 254 to +255
renamed_command,
renamed_command_in_mod,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How abort export same function name from different module?

A::renamed_command,
B::renamed_command,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no way to support all use cases :/ not exporting macros breaks some other scenarios (like importing the function and then using it directly IIRC)

@lucasfernog
lucasfernog merged commit c00a3db into tauri-apps:dev Apr 30, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants