Skip to content

feat: bundle type detection at runtime via binary patching#13209

Merged
lucasfernog merged 19 commits intotauri-apps:devfrom
kandrelczyk:feature/binary_patch_bundle_types
Jul 7, 2025
Merged

feat: bundle type detection at runtime via binary patching#13209
lucasfernog merged 19 commits intotauri-apps:devfrom
kandrelczyk:feature/binary_patch_bundle_types

Conversation

@kandrelczyk
Copy link
Contributor

@kandrelczyk kandrelczyk commented Apr 11, 2025

This is first PR to address tauri-apps/plugins-workspace#2277

Thanks to this the updater plugin will be able to determine which installer to download.

There is a breaking change here requiring updater plugin and tauri-cli to be compatible since we need __TAURI_BUNDLE_TYPE variable to be present in the binary. In case the variable is not found error is reported. Not sure if it's ok or if we need a better solution here.

@kandrelczyk kandrelczyk requested a review from a team as a code owner April 11, 2025 20:18
@github-project-automation github-project-automation bot moved this to 📬Proposal in Roadmap Apr 11, 2025
// bundle was already built! e.g. DMG already built .app
if bundles.iter().any(|b| b.package_type == *package_type) {
continue;
} // REMOVE THIS?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about this. This only applies to DMG, right? We don't want to skip anything on linux or windows as the binary needs to be patched for each type anyway.

.idea
debug.log
TODO.md
.aider*
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for those weird patches. I think this is line end issue because I worked on both windows and linux. I only added '.aider*' here.

Copy link
Contributor

Choose a reason for hiding this comment

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

You probably want to set autocrlf to true or input

git config --global core.autocrlf true/git config --global core.autocrlf input
https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#:~:text=with%20these%20issues.-,core.autocrlf,-If%20you%E2%80%99re%20programming

HashError,
/// Failed to parse binary
#[error("Binary parse error: `{0}`")]
BinaryParseError(String),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same line end issue. New errors are here.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 12, 2025

Package Changes Through 4ff1d8c

There are 4 changes which include @tauri-apps/api with patch, tauri-cli with patch, tauri-bundler with patch, tauri-utils with patch

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.6.0 2.6.1
tauri-utils 2.5.0 2.5.1
tauri-bundler 2.5.0 2.5.1
tauri-runtime 2.7.0 2.7.1
tauri-runtime-wry 2.7.1 2.7.2
tauri-codegen 2.3.0 2.3.1
tauri-macros 2.3.1 2.3.2
tauri-plugin 2.3.0 2.3.1
tauri-build 2.3.0 2.3.1
tauri 2.6.2 2.6.3
@tauri-apps/cli 2.6.2 2.6.3
tauri-cli 2.6.2 2.6.3

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


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

mod updater_bundle;
mod windows;

impl From<goblin::error::Error> for crate::error::Error {
Copy link
Member

Choose a reason for hiding this comment

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

this can be done inside crate::error::Error::BinaryParseError by leverating thiserror #[from] attribute

@lucasfernog
Copy link
Member

i think we should consider using https://github.com/denoland/sui it has an easy to use API

@kandrelczyk
Copy link
Contributor Author

kandrelczyk commented Apr 13, 2025

i think we should consider using https://github.com/denoland/sui it has an easy to use API

Definitely looks simpler than goblin. Wish I knew about it before :)

Should I just change the patching implementation?

@kandrelczyk
Copy link
Contributor Author

@lucasfernog I've pushed some of the suggested changes. I decided no to use sui as this would add dependency to the app, not just the builder. If there anything else missing here?

@FabianLars FabianLars added this to the 2.6 milestone May 31, 2025
@FabianLars FabianLars modified the milestones: 2.6, 2.7 Jun 27, 2025
@lucasfernog lucasfernog changed the title Feature/binary patch bundle types feat: bundle type detection at runtime via binary patching Jul 7, 2025
Copy link
Member

@lucasfernog lucasfernog left a comment

Choose a reason for hiding this comment

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

awesome

@lucasfernog lucasfernog merged commit 232265c into tauri-apps:dev Jul 7, 2025
29 checks passed
@github-project-automation github-project-automation bot moved this from 📬Proposal to 🔎 In audit in Roadmap Jul 7, 2025
@Legend-Master
Copy link
Contributor

Didn't look at it yet, but it seems like the ubuntu build is failing https://github.com/tauri-apps/tauri/actions/runs/16120739808/job/45485616619

@kandrelczyk
Copy link
Contributor Author

@Legend-Master I've just checked and the tests I added to plugins-workspace/plugins/updater/tests/app-updater still pass. I will check the build ASAP.

catalinsh pushed a commit to catalinsh/tauri that referenced this pull request Jul 10, 2025
@kandrelczyk
Copy link
Contributor Author

kandrelczyk commented Jul 10, 2025

@Legend-Master pushed the fix. Turns out my tests used --debug but the failing test don't. In release mode the bundle type variable was stripped even though it's referenced in public method. I've added #[used] to it and release builds work now.

...Now I see this PR was closed already. Do I have to create a new PR with the fix?

@Legend-Master
Copy link
Contributor

...Now I see this PR was closed already. Do I have to create a new PR with the fix?

Yeah, that's how we usually do it

@kandrelczyk
Copy link
Contributor Author

@Legend-Master Submitted here: #13808

@kittuov
Copy link
Contributor

kittuov commented Jul 22, 2025

Hey, Looks like the patcher is modifying the binary after code signing. This is rendering the signing to be invalid. maybe move the signing to after binary is patched?

@kandrelczyk
Copy link
Contributor Author

@kittuov Hey, can you point me to the place were we sign the binary? I'm only familiar wit generating the signatures files for the bundles.

@Legend-Master
Copy link
Contributor

Legend-Master commented Jul 22, 2025

@kittuov Hey, can you point me to the place were we sign the binary? I'm only familiar wit generating the signatures files for the bundles.

It was signing the main executable on Windows (you sign both the binaries and the bundles on Windows instead of just the bundles on Linux, and we don't do binary patching on macOS yet), should be fixed in #13870 (we sign the binaries first before generating all the bundles, but now we need to sign them after the binary patching)

Thanks for taking a look anyways 🙃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎 In audit

Development

Successfully merging this pull request may close these issues.

5 participants