摘要
在macOS(arm64)平臺打包tauri程式到Windows(amd64)平臺.
Abstract
Packaging a Tauri application for the Windows (amd64) platform from macOS (arm64).
關鍵資訊
- 構建平臺:macOS 14.6.1 (arm64)
- 目標平臺:Window10 (amd64)
原理簡介
nsis簡介
[https://nsis.sourceforge.io/Docs/Chapter1.html#intro-about]
The installer is your application's first impression. Slow or unsuccessful software installations is one of the most irritating computer problems. A quick and user friendly installer is therefore an essential part of your software product. NSIS (Nullsoft Scriptable Install System) is a tool that allows programmers to create such installers for Windows. It is released under an open source license and is completely free for any use.
NSIS creates installers that are capable of installing, uninstalling, setting system settings, extracting files, etc. Because it's based on script files you can fully control every part of your installer. The scripting language supports variables, functions and string manipulation, just like a normal programming language - but designed for the creation of installers. Even with all these features, NSIS is still the smallest installer system available. With the default options, it has an overhead of only 34 KB.
Starting with NSIS v3.0 you can choose to create Unicode installers by setting the Unicode attribute. These installers will not work on Windows 95/98/ME but they will allow you to display your installer in any Unicode language supported by the OS.
When building a Unicode installer NSIS variables can hold Unicode characters (0001-FFFF). There should be no need to modify your existing scripts. If you want to read/write Unicode files, specific instructions have been added to read/write UTF-16LE strings from/to disk.
安裝程式是您的應用程式的第一印象。軟體安裝緩慢或失敗是計算機問題中最令人煩惱的之一。因此,一個快速且使用者友好的安裝程式是您的軟體產品的重要組成部分。NSIS(Nullsoft Scriptable Install System)是一個允許程式設計師為Windows建立此類安裝程式的工具。它是在開源許可下發布的,可以完全免費使用。
NSIS建立的安裝程式能夠安裝、解除安裝、設定系統設定、提取檔案等。因為它基於指令碼檔案,所以您可以完全控制安裝程式的每一個部分。指令碼語言支援變數、函式和字串操作,就像普通的程式語言一樣,但它是為建立安裝程式而設計的。即使擁有所有這些功能,NSIS仍然是可用的最小安裝程式系統。使用預設選項,它只有34 KB的開銷。
從NSIS v3.0開始,您可以選擇透過設定Unicode屬性來建立Unicode安裝程式。這些安裝程式在Windows 95/98/ME上無法工作,但它們將允許您在作業系統支援的任何Unicode語言中顯示您的安裝程式。
在構建Unicode安裝程式時,NSIS變數可以儲存Unicode字元(0001-FFFF)。您應該不需要修改現有的指令碼。如果您想要讀寫Unicode檔案,已經新增了特定的指令來從磁碟讀取/寫入UTF-16LE字串。
msvc簡介
[https://zhuanlan.zhihu.com/p/702329030]
簡單的說:MSVC 是微軟 C/C++ 語言以及相關工具集
語言相關包括:MSVC++ 語言 ,MSVC C++ 庫(微軟自稱 STL:C++ standard library,是的,不是你理解的那個 stl )。
相關工具及包括了:編譯連結工具 cl.exe link.exe rc.exe 等。
廣義上講,Windows SDK 包括了在對應版本作業系統的標頭檔案和系統的匯入庫,最終指向了可能包括了 Kernel32.dll、 Advapi32.dll 等,我們可以稱之為 Win32 子系統動態連結庫,(Windows 包括多個子系統,甚至包括 POSIX 子系統 ).
在這個過程中 SDK 只是一些可能包括了一些引數檢查,轉換引數,呼叫內部函式 如 CreateFile 最終經過一系列操作後,最後呼叫了 NtCreateFile 函式,該函式並不存在於 SDK ,甚至不存在於 Win32 subsystem 的 dll 中,而是存在於 ntdll.dll 中(native dll),在這裡發生了真正的系統呼叫,並最終根據系統呼叫號系統呼叫。
tauri跨平臺打包
[https://v1.tauri.app/v1/guides/building/cross-platform/]
[https://nsis.sourceforge.io/Docs/AppendixG.html]
[https://nsis-dev.github.io/NSIS-Forums/html/t-276382.html]
[https://github.com/jcsteh/osara/issues/89]
[https://github.com/ContinuumIO/anaconda-recipes/issues/86]
Tauri v1.3 added a new Windows installer type based on the NSIS installer framework. In contrast to WiX, NSIS itself can also work on Linux and macOS which makes it possible to build many Tauri apps on non-Windows hosts. Note that this is currently considered highly experimental and may not work on every system or for every project. Therefore it should only be used as a last resort if local VMs or CI solutions like GitHub Actions don't work for you. Note that, at this time, signing cross-platform builds is currently unsupported.
Tauri v1.3增加了一種新的Windows安裝程式型別,基於NSIS安裝程式框架。與WiX不同,NSIS本身也可以在Linux和macOS上執行,這使得在非Windows主機上構建許多Tauri應用程式成為可能。請注意,這目前被認為是高度實驗性的,可能不會在每一個系統或每一個專案中都有效。因此,它應該只作為最後的手段使用,如果本地虛擬機器或CI解決方案(如GitHub Actions)對您不起作用的話。請注意,目前不支援對跨平臺構建進行簽名。
實現
步驟
cargo create-tauri-app
# ✔ Project name · tauri-app
# ✔ Identifier · com.tauri-app.app
# ✔ Choose which language to use for your frontend · TypeScript / JavaScript - (pnpm, yarn, npm, bun)
# ✔ Choose your package manager · npm
# ✔ Choose your UI template · Vue - (https://vuejs.org/)
# ✔ Choose your UI flavor · JavaScript
npm run tauri dev
brew install nsis
rustup target add x86_64-pc-windows-msvc
cargo install --locked cargo-xwin
sudo mkdir /opt/homebrew/Cellar/makensis/3.10/share/nsis
sudo cp -r /opt/homebrew/Homebrew/Cellar/makensis/3.10/share/nsis/** /opt/homebrew/Cellar/makensis/3.10/share/nsis
npm run tauri build -- --runner cargo-xwin --target x86_64-pc-windows-msvc
效果
成功在Windows執行 |
---|
聯絡方式
如果對本文有疑問或者提出建議可評論區留言或者傳送郵件到2557877116@qq.com.