zadam / trilium

Build your personal knowledge base with Trilium Notes
GNU Affero General Public License v3.0
27.17k stars 1.9k forks source link

(Feature request) I want a version for mac m1 chip #3302

Open supermanmsc opened 1 year ago

supermanmsc commented 1 year ago

Describe feature

(Feature request) I want a version for mac m1 chip

Additional Information

(Feature request) I want a version for mac m1 chip

zadam commented 1 year ago

Unlikely to happen soon, if ever.

If I understand correctly, Apple tightened the screws and M1 apps require notarization (besides also needing to be built on M1). From my experience, the Intel build works decently well through Rosetta.

supermanmsc commented 1 year ago

Unlikely to happen soon, if ever.

If I understand correctly, Apple tightened the screws and M1 apps require notarization (besides also needing to be built on M1). From my experience, the Intel build works decently well through Rosetta.

Thanks for you attention , i hava a core dump case. either caused by m1 or not . https://github.com/zadam/trilium/issues/3307

Myzel394 commented 1 year ago

@supermanmsc Trilium works mine for me on my M1 mac (2020 version) - Did you try running it with and without rosetta?

delight commented 1 year ago

Unlikely to happen soon, if ever.

If I understand correctly, Apple tightened the screws and M1 apps require notarization (besides also needing to be built on M1). From my experience, the Intel build works decently well through Rosetta.

Could you please elaborate on what you mean by tightened screws and required notarization. There are galore open source projects and commercial programs available for Apple Silicon by now. As I understand this is an electron app. This should be a big problem to get this working on an M1/M2. I uninstalled every non native app by now ... some things are missing but (at least for me) its way less then 5% of apps that are not available in a native Version. Kodi being one of them and they plan to support M1 in the next version. Technically this project should be portable way easier.

zadam commented 1 year ago

@delight

It's been a while since I researched that, but IIRC:

IIRC this was complicated by the fact that the Apple policy kind of legally prevents renting Macs for CI (or something like that).

I don't doubt that many FOSS projects manage to do that, perhaps they have more manpower or perhaps bigger focus on Mac platform. But Trilium is essentially a one-man show and the overhead of running the builds separately on MacOS isn't very attractive for me, especially given that the rosetta emulation of the x86 build works pretty well.

Of course, if somebody is willing to do this (i.e. do the release builds and notarization), then that would be awesome!

delight commented 1 year ago

I think the apple certificate is only need if you want to distribute the app via the app store. It's not the case for simple downloads from a webpage or installations via brew. There are big and small open source projects without certificates. I could list you some or you could have a look at the list of brew apps.

Obviously there is this button in system settings where you have to agree to run the app even though it's not certified. I even disabled that hate keeper completely because I know that I'm doing and it's annoying otherwise to confirm every second app.

delight commented 1 year ago

Of course, if somebody is willing to do this (i.e. do the release builds and notarization), then that would be awesome!

I would like to give it a try to build the binaries.

@zadam do you have some build instructions or can give me some here ?

I'll just give it a shot in the meantime:

$ pnpm i
 WARN  deprecated electron-rebuild@3.2.9: Please use @electron/rebuild moving forward.  There is no API change, just a package name change
 WARN  deprecated csurf@1.11.0: Please use another csrf package
 WARN  deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
 WARN  deprecated har-validator@5.1.5: this library is no longer supported
 WARN  deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
 WARN  deprecated electron-osx-sign@0.6.0: Please use @electron/osx-sign moving forward. Be aware the API is slightly different
 WARN  deprecated asar@3.2.0: Please use @electron/asar moving forward.  There is no API change, just a package name change
Downloading registry.npmjs.org/app-builder-bin/4.0.0: 45.1 MB/45.1 MB, done
 WARN  deprecated @npmcli/move-file@2.0.1: This functionality has been moved to @npmcli/fs

a bunch of deprecation warnings came up right aways for a start

especially:

Just noting... let's see how far I'll get

zadam commented 1 year ago

You can use bin/build-mac.sh as a reference

delight commented 1 year ago

I think I need a little bit more then that

zadam commented 1 year ago

this script won't create the ./dist/trilium-mac-x64-src folder etc.

It does the whole build process all the way until creating the final ZIP file.

... how about if you add a BuildFromSource.md to the sources ?

There is a guide for "server installation" for Debian based systems - https://github.com/zadam/trilium/wiki/Manual-server-installation

But in general I don't really plan to support that. Building from source differs between OSs (including different linux distros), system dependencies changing between OS versions etc. It's a nightmare to maintain.

NyaomiDEV commented 1 year ago

To build on Mac M1 you need

in my case I also used nvm to use node 16.18, so I removed all "n exec 16.18.0" calls from copy-trilium.sh and just replaced them with plain npm calls, as my environment was already using 16.18.0 via nvm.

so yeah its doable

EDIT: btw, here is a patch

``` From d391c5e64f3068b0e0162e9ab19a7b8cba8a730b Mon Sep 17 00:00:00 2001 From: Naomi Calabretta Date: Wed, 7 Dec 2022 19:17:49 +0100 Subject: [PATCH] build on mac m1 --- bin/build-mac-arm64.sh | 38 ++++++++++++++++++++++++++++++++++++++ bin/copy-trilium.sh | 6 +++--- 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100755 bin/build-mac-arm64.sh diff --git a/bin/build-mac-arm64.sh b/bin/build-mac-arm64.sh new file mode 100755 index 00000000..27b5a1ae --- /dev/null +++ b/bin/build-mac-arm64.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +SRC_DIR=./dist/trilium-mac-arm64-src + +if [ "$1" != "DONTCOPY" ] +then + ./bin/copy-trilium.sh $SRC_DIR +fi + +echo "Copying required mac binaries" + +(cd "$SRC_DIR" && npm run switch-electron) + +rm -r $SRC_DIR/src/public/app-dist/*.mobile.* + +echo "Packaging mac arm64 electron build" + +./node_modules/.bin/electron-packager $SRC_DIR --asar --out=dist --executable-name=trilium --platform=darwin --arch=arm64 --overwrite --icon=images/app-icons/mac/icon.icns + +BUILD_DIR=./dist/trilium-mac-arm64 +rm -rf $BUILD_DIR + +# Mac build has by default useless directory level +mv "./dist/Trilium Notes-darwin-arm64" $BUILD_DIR + +cp bin/tpl/anonymize-database.sql $BUILD_DIR/ + +cp -r dump-db $BUILD_DIR/ +rm -rf $BUILD_DIR/dump-db/node_modules + +echo "Zipping mac arm64 electron distribution..." + +VERSION=`jq -r ".version" package.json` + +cd dist + +rm trilium-mac-arm64-${VERSION}.zip +zip -r9 --symlinks trilium-mac-arm64-${VERSION}.zip trilium-mac-arm64 diff --git a/bin/copy-trilium.sh b/bin/copy-trilium.sh index 77f754d1..7ee35af3 100755 --- a/bin/copy-trilium.sh +++ b/bin/copy-trilium.sh @@ -5,12 +5,12 @@ if [[ $# -eq 0 ]] ; then exit 1 fi -n exec 16.18.0 npm run webpack +npm run webpack DIR=$1 rm -rf $DIR -mkdir $DIR +mkdir -p $DIR echo "Copying Trilium to build directory $DIR" @@ -27,7 +27,7 @@ cp -r electron.js $DIR/ cp webpack-* $DIR/ # run in subshell (so we return to original dir) -(cd $DIR && n exec 16.18.0 npm install --only=prod) +(cd $DIR && npm install --only=prod) # cleanup of useless files in dependencies rm -r $DIR/node_modules/image-q/demo -- 2.37.1 (Apple Git-137.1) ```
thanhtam4692 commented 11 months ago

I'm able to build for arm64 (M1 chip) with this script:

#!/usr/bin/env bash

SRC_DIR=./dist/trilium-mac-arm64-src

if [ "$1" != "DONTCOPY" ]; then
    ./bin/copy-trilium.sh $SRC_DIR
fi

cd "$SRC_DIR" && npm install

mkdir ./build
cp ./images/app-icons/mac/icon.icns ./build/

./node_modules/.bin/electron-builder build --mac --arm64

You will get the build from this dist folder inside the dist folder: ./dist/trilium-mac-arm64-src/dist/mac-arm64/Trilium Notes.app It's actually quite simple. I tried the script on the comment above but it failed, and it seems like better-sqlite3 still built with x64 arch instead of arm64 because of some bug (I'm building it in my M1). However, using electron-builder, it can rebuilt all dependencies including better-sqlite3 into arm64. And you'll get a dmg package for it too. This is lacking of dump db and other stuff but I don't use them anyway (I'm not sure that they do too)

jinxiaoman commented 7 months ago
image

I just built a version of m2 to experience it for a while. So far:

  1. the build size increased by more than 100MB,
  2. the user experience has been greatly upgraded, before I had to wait 10s for startup on m2, now it starts instantly in any situation.
  3. Memory footprint still has a short time of use left. Current note size 100mb
image
leesandao commented 3 months ago
image

I just built a version of m2 to experience it for a while. So far:

  1. the build size increased by more than 100MB,
  2. the user experience has been greatly upgraded, before I had to wait 10s for startup on m2, now it starts instantly in any situation.
  3. Memory footprint still has a short time of use left. Current note size 100mb
image

can you guide on how to build on M2 MAC?

jinxiaoman commented 3 months ago
image

I just built a version of m2 to experience it for a while. So far:

  1. the build size increased by more than 100MB,
  2. the user experience has been greatly upgraded, before I had to wait 10s for startup on m2, now it starts instantly in any situation.
  3. Memory footprint still has a short time of use left. Current note size 100mb
image

can you guide on how to build on M2 MAC?

Of course you can. In fact, the latest repositories now include scripts for arm64 builds, so you can try them out. There are a few caveats:

  1. The node version in the build script, if you have a local environment, you can directly use the local environment, usually 18.0+ will work.
  2. After the build, the client size is about 430M, so you need to trust it manually for local installation. If you fail, I can provide you with a built version, so try to build it yourself.
leesandao commented 3 months ago
image

I just built a version of m2 to experience it for a while. So far:

  1. the build size increased by more than 100MB,
  2. the user experience has been greatly upgraded, before I had to wait 10s for startup on m2, now it starts instantly in any situation.
  3. Memory footprint still has a short time of use left. Current note size 100mb
image

can you guide on how to build on M2 MAC?

Of course you can. In fact, the latest repositories now include scripts for arm64 builds, so you can try them out. There are a few caveats:

  1. The node version in the build script, if you have a local environment, you can directly use the local environment, usually 18.0+ will work.
  2. After the build, the client size is about 430M, so you need to trust it manually for local installation. If you fail, I can provide you with a built version, so try to build it yourself.

I have already use Trilium Server on my QNAP NAS as docker running, I want to have a Client Desktop app to work in offline mode. Sorry I am a newbie in this area, I tried the latest build script, but it looks like everything is not working in my M2 mac rali@Raynors-MacBook-Pro bin % ./build-mac-arm64.sh ./build-mac-arm64.sh: line 7: ./bin/copy-trilium.sh: No such file or directory Copying required mac arm64 binaries cp: bin/better-sqlite3/mac-arm64-better_sqlite3.node: No such file or directory rm: ./dist/trilium-mac-arm64-src/src/public/app-dist/.mobile.: No such file or directory Packaging mac arm64 electron build ./build-mac-arm64.sh: line 18: ./node_modules/.bin/electron-packager: No such file or directory mv: rename ./dist/Trilium Notes-darwin-arm64 to ./dist/trilium-mac-arm64: No such file or directory cp: directory ./dist/trilium-mac-arm64 does not exist cp: directory ./dist/trilium-mac-arm64 does not exist Zipping mac arm64 electron distribution... ./build-mac-arm64.sh: line 33: jq: command not found ./build-mac-arm64.sh: line 35: cd: dist: No such file or directory rm: trilium-mac-arm64-.zip: No such file or directory zip warning: name not matched: trilium-mac-arm64

zip error: Nothing to do! (try: zip -r9 --symlinks trilium-mac-arm64-.zip . -i trilium-mac-arm64) rali@Raynors-MacBook-Pro bin %

leesandao commented 3 months ago

another try `rali@Raynors-MacBook-Pro trilium % sudo ./bin/build-mac-arm64.sh ./bin/copy-trilium.sh: line 12: n: command not found

trilium@0.63.6 webpack webpack -c webpack.config.js

asset desktop.js 652 KiB [compared for emit] [minimized] (name: desktop) 2 related assets asset mobile.js 366 KiB [compared for emit] [minimized] (name: mobile) 1 related asset asset 760.js 139 KiB [compared for emit] [minimized] 1 related asset asset 41.js 109 KiB [compared for emit] [minimized] 1 related asset asset setup.js 10.7 KiB [compared for emit] [minimized] (name: setup) 1 related asset asset 317.js 6.66 KiB [compared for emit] [minimized] 1 related asset asset 749.js 2.22 KiB [compared for emit] [minimized] 1 related asset asset 784.js 1.96 KiB [compared for emit] [minimized] 1 related asset orphan modules 944 KiB [orphan] 225 modules runtime modules 16.9 KiB 24 modules built modules 1.77 MiB [built] modules by path ./src/public/app/services/ 171 KiB 34 modules modules by path ./src/public/app/menus/.js 22.1 KiB 5 modules modules by path ./src/public/app/widgets/ 255 KiB 4 modules modules by path ./src/public/app/entities/.js 36.4 KiB 4 modules modules by path ./src/public/app/*.js 1.24 MiB ./src/public/app/setup.js + 1 modules 3.53 KiB [built] [code generated]

WARNING in ./src/public/app/services/utils.js 295:15-34 Critical dependency: the request of a dependency is an expression @ ./src/public/app/setup.js 1:0-40 86:12-28 87:27-47 92:12-35

1 warning has detailed information that is not shown. Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

webpack 5.93.0 compiled with 1 warning in 2263 ms ./dist/trilium-mac-arm64-src Copying Trilium to build directory ./dist/trilium-mac-arm64-src cp: webpack-: No such file or directory ./bin/copy-trilium.sh: line 30: n: command not found Copying required mac arm64 binaries cp: ./dist/trilium-mac-arm64-src/node_modules/better-sqlite3/build/Release/better_sqlite3.node: No such file or directory rm: ./dist/trilium-mac-arm64-src/src/public/app-dist/.mobile.*: No such file or directory Packaging mac arm64 electron build ./bin/build-mac-arm64.sh: line 18: ./node_modules/.bin/electron-packager: No such file or directory mv: rename ./dist/Trilium Notes-darwin-arm64 to ./dist/trilium-mac-arm64: No such file or directory cp: directory ./dist/trilium-mac-arm64 does not exist Zipping mac arm64 electron distribution... ./bin/build-mac-arm64.sh: line 33: jq: command not found rm: trilium-mac-arm64-.zip: No such file or directory adding: trilium-mac-arm64/ (stored 0%) adding: trilium-mac-arm64/inc/ (stored 0%) adding: trilium-mac-arm64/inc/decrypt.js (deflated 61%) adding: trilium-mac-arm64/inc/data_key.js (deflated 57%) adding: trilium-mac-arm64/inc/sql.js (deflated 61%) adding: trilium-mac-arm64/inc/dump.js (deflated 71%) adding: trilium-mac-arm64/inc/extension.js (deflated 58%) adding: trilium-mac-arm64/dump-db.js (deflated 58%) adding: trilium-mac-arm64/README.md (deflated 50%) adding: trilium-mac-arm64/package-lock.json (deflated 84%) adding: trilium-mac-arm64/package.json (deflated 48%)`

leesandao commented 3 months ago

Node version is latest

rali@Raynors-MacBook-Pro trilium % node -v v22.4.1

leesandao commented 3 months ago

although it cannot run

image
jinxiaoman commented 3 months ago

although it cannot run image

in my case I also used nvm to use node 16.18, so I removed all "n exec 16.18.0" calls from copy-trilium.sh and just replaced them with plain npm calls, as my environment was already using 16.18.0 via nvm.

Reference above: in my case I also used nvm to use node 16.18, so I removed all "n exec 16.18.0" calls from copy-trilium.sh and just replaced them with plain npm calls, as my environment was already using 16.18.0 via nvm.

It is recommended to use node 18, 1. Modify the script content: do not use pnpm Modify to npm, do not n manage.

image
meichthys commented 3 months ago

@leesandao and @jinxiaoman We'd love to support as many platforms as reasonably possible over on Trilium-Next We have some folks working on the build scripts now, so you may be able to build off of their work to get a working build.

https://github.com/TriliumNext/Notes

leesandao commented 3 months ago

although it cannot run image

in my case I also used nvm to use node 16.18, so I removed all "n exec 16.18.0" calls from copy-trilium.sh and just replaced them with plain npm calls, as my environment was already using 16.18.0 via nvm.

Reference above: in my case I also used nvm to use node 16.18, so I removed all "n exec 16.18.0" calls from copy-trilium.sh and just replaced them with plain npm calls, as my environment was already using 16.18.0 via nvm.

It is recommended to use node 18, 1. Modify the script content: do not use pnpm Modify to npm, do not n manage.

image

Thanks! Finally, I got the correct build, but it looks like cannot run, only a icon in dock is running...but no display any console image image

leesandao commented 3 months ago

After rebooting, it works now, thanks

image
jinxiaoman commented 3 months ago

After rebooting, it works now, thanks

image

Great, let‘s have a good experience next.