tauri icon indicating copy to clipboard operation
tauri copied to clipboard

feat(nsis): add an option to opt out tauri utils plugin

Open Legend-Master opened this issue 2 years ago • 11 comments

Add an option to replace nsis util plugin with built-in ones, this can reduce the final bundle size by ~0.8 MB

Downsides including:

  • Can't compare semver like 2.0.0-alpha.1
  • No Windows 7 support when using downloadBootstrapper option due to Windows 7 ~~doesn't have curl installed by default~~ doesn't have tls 1.2 enabled by default (this option is not recommended for Windows 7 anyway)

Legend-Master avatar Apr 21 '24 02:04 Legend-Master

I need to take a look at the CheckIfAppIsRunning part, it's not actually detecting the app right now

Legend-Master avatar Apr 21 '24 16:04 Legend-Master

I need to take a look at the CheckIfAppIsRunning part, it's not actually detecting the app right now

Should be fixed now

Legend-Master avatar Apr 22 '24 01:04 Legend-Master

I still would like to explore reducing the size of our semverCompare and process utils, I believe we can probably make these two plugins really small that we wouldn't need to use the alternatives.

I compiled it without the download one, it's around 200 KB, not too bad but definitely something we could improve

Legend-Master avatar Apr 22 '24 13:04 Legend-Master

I still would like to explore reducing the size of our semverCompare and process utils, I believe we can probably make these two plugins really small that we wouldn't need to use the alternatives.

I compiled it without the download one, it's around 200 KB, not too bad but definitely something we could improve

A 100kb of that are related to static CRT iirc

amrbashir avatar Apr 22 '24 13:04 amrbashir

Sorry for the long delay, I wanted to experiment a bit and see if we can avoid having this option.

I have been doing some experiments and I have managed to reduce the size of some of our nsis plugins:

nsis-semvercompare nsis-process nsis-semvercompare & nsis-process combined in one DLL
dev 198kb 208kb 200kb
no_std 35kb 48kb 53kb
no_std (UPX) 20kb 26kb 29kb

So I think we can keep using our nsis-process and nsis-semvercompare without compromising while keeping the size very small.

The remaining bit here is the nsis-download plugin which is the most bloated of them all and unfortunately can't be written in a no_std environment, at least without too much work.

So I am proposing to remove it all together and use powershell to download the bootstrapper, this means it will fail on Windows7 and so we will need to recommend users to use embedBootstrapper when targeting Windows7.

If that's not desired, we can make this PR add an opt-out option specifically for the nsis-download plugin.

cc @lucasfernog @FabianLars

amrbashir avatar Apr 23 '24 17:04 amrbashir

I think requiring embedBootstrapper for windows 7 is fine. We shouldn't do more than the minimum for win7 at this point imo (and remove support for it in v3).

One thing though, i am fairlyyy sure i've had issues without our download plugin on win10 too so we should triple check it! We should also check if using powershell will open a terminal window again which tbh would be a blocker for me too.

FabianLars avatar Apr 23 '24 19:04 FabianLars

One thing though, i am fairlyyy sure i've had issues without our download plugin on win10 too so we should triple check it! We should also check if using powershell will open a terminal window again which tbh would be a blocker for me too.

using nsExec::Exec with PowerShell.exe -WindowStyle hidden should not show it.

But the one thing I hate about this is that we lose the progress bar.

amrbashir avatar Apr 24 '24 00:04 amrbashir

no std version seem to be promising, 50 KB is acceptable

To be honest, if we can't reduce the download plugin's size enough, there'll not be much benefit doing it this way, the bootstrap is only 1.5 MB

using nsExec::Exec with PowerShell.exe -WindowStyle hidden should not show it.

I'm pretty sure nsExec::Exec powershell -Command alone creates a hidden window

Legend-Master avatar Apr 24 '24 01:04 Legend-Master

The problem i am thinking about is that when ms terminal is the default console host then the hidden window style doesn't work anymore. On win11 this isn't a problem as long as we're only downloading webview2 since all win11 installations should have that, but win10 added support for changing the default to ms terminal in later versions too and there we can't expect webview2 to be installed.

FabianLars avatar Apr 24 '24 08:04 FabianLars

I'm pretty sure nsExec::Exec powershell -Command will create a hidden window even when you set windows terminal as default console host, I have tested this on my machine (windows 10) as least

Legend-Master avatar Apr 24 '24 08:04 Legend-Master

I have been tinkering over the weekend a bit and I managed to get the dlls even smaller

nsis-semvercompare nsis-process nsis-semvercompare & nsis-process combined in one DLL
dev 198kb 208kb 200kb
no_std 35kb 48kb 53kb
no_std+upx 20kb 26kb 29kb
no_std/no_msvcrt 10kb 22kb 27kb
no_std/no_msvcrt+upx 7kb 13kb 16kb

I don't think I can get them smaller than this, so I will start looking into the download plugin

amrbashir avatar Apr 27 '24 14:04 amrbashir

I don't know how I missed this before but looks like nsis has a built-in download plugin that is able to download the webview2 installer which is also really small in size

amrbashir avatar Apr 29 '24 17:04 amrbashir

I apologize for initially asking you to open this PR then rejecting it. I have opened https://github.com/tauri-apps/nsis-tauri-utils/pull/26 for the small dll size

amrbashir avatar Apr 29 '24 17:04 amrbashir

I don't know how I missed this before but looks like nsis has a built-in download plugin that is able to download the webview2 installer which is also really small in size

Its first line says

This built-in plugin allows you to download files via HTTP (but not HTTPS).

I did come across this but it says no HTTPS

I apologize for initially asking you to open this PR then rejecting it.

It's fine, glad to accept a better solution 😃

Legend-Master avatar Apr 30 '24 01:04 Legend-Master

I did come across this but it says no HTTPS

That's probably why it works on win7 because https will fail, though i am surprised a http request against a https url works, probably only a matter of time until this breaks so we should keep an eye on it.

FabianLars avatar Apr 30 '24 10:04 FabianLars