Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support compiling native MacOS arm64 (Apple Silicon) builds #4772

Merged
merged 2 commits into from
May 30, 2024

Conversation

gigamonster256
Copy link
Contributor

Following along with the original request in #3125 and the followup plus community troubleshooting in #3302, I was able to successfully build a working native arm64 build of trilium for MacOS on my M1 mac as well using my Windows 11 wsl environment.

Using the native package rather than relying on the Rosetta translation layer leads to a much better startup time (a couple seconds at most vs 10-20 seconds before) and a much snappier experience. (as originally reported in #3302)

A user in #3302 voiced concerns about an arm64 native build being bigger than the x86-64 build, but their observations seem to come from using a different packaging system than trilium uses for its other builds. I replicated the current build flow for arm64 and the resulting binaries are comparable to the released build sizes. (See below)

Screenshot 2024-05-18 at 3 38 18 AM I built both the latest and second latest versions of trilium to test. The top row of applications was compiled by me (both intel and arm builds) and the bottom are from the trilium releases.

Concerning future maintainability, better-sqlite3 does not have prebuilt binaries for version 8.4.0 with electron 25 so I compiled that combination myself for macos arm64 and added it to the precompiled binaries used for trilium releases. If in future releases of trilium the version of electron and/or better-sqlite3 is changed, precompiled binaries will most likely be available through better-sqlite3 releases, removing the need for an Apple Silicon computer to keep arm64 builds up to date.

@meichthys
Copy link
Collaborator

meichthys commented May 18, 2024

Get work! Do you have a sense of how difficult it would be to also build a Linux arm 64 build? I attempted it a few times but haven't been successful.

@gigamonster256
Copy link
Contributor Author

Get work! Do you have a sense of how difficult it would be to also build a Linux arm 64 build? I attempted it a few times but haven't been successful.

Based on my very limited understanding of electron apps (literally all learned trying to get this working) the only prebuilt architecture dependent component that changes between trilium builds is the better-sqlite3 database bindings. It seems that the main workhorse of the packaging, electron-packager, is able to "cross-compile" everything else (as much as you can compile an electron app.) Unfortunately the bindings of better-sqlite3 8.4.0 with electron 25 (NODE_MODULE_VERSION = 116 and what trilium currently uses) are not available as binaries from the developers so I had to build it on a native platform to get maxos arm64 working. It looks like all that is needed to get linux_arm64 working is to make/find a copy of the correctly versioned better_sqlite3.node file for linux_arm64 and add/modify the build scripts like I did in this pull request to add it.

Interestingly enough, it seems that electron-packager does not support building on linux_arm64 but does support it as a target so you'd need to build on a supported system then bring the zip over to the arm linux device.

gigamonster256 added a commit to gigamonster256/nixpkgs that referenced this pull request May 22, 2024
Currently, trilium-desktop is supported on aarch64-darwin through
Rosetta. Native support is awaiting review of my upstream PR:
zadam/trilium#4772
gigamonster256 added a commit to gigamonster256/nixpkgs that referenced this pull request May 22, 2024
Currently, trilium-desktop is supported on aarch64-darwin through
Rosetta. Native support is awaiting review of my upstream PR:
zadam/trilium#4772
@zadam
Copy link
Owner

zadam commented May 30, 2024

That's great, thanks for the contribution. I was under impression that building an M1 electron package required building on M1.

@zadam zadam merged commit 8ebebec into zadam:master May 30, 2024
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.

None yet

3 participants