折腾笔记[2]-跨平台打包tauri程序

摘要

在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.
分割线

posted @ 2024-10-06 13:18  qsBye  阅读(82)  评论(0编辑  收藏  举报