transgui icon indicating copy to clipboard operation
transgui copied to clipboard

M1 macOS build?

Open Willian-Zhang opened this issue 3 years ago • 87 comments

Apple m1 lines Macs are out, is there a easy way to build a m1 native app?

Operating system: macOS Big Sur 11.0.1 (20B29)

Willian-Zhang avatar Nov 21 '20 14:11 Willian-Zhang

Since there is no building guide provided for macOS, https://github.com/transmission-remote-gui/transgui/pull/1224 and https://wiki.freepascal.org/macOS_Big_Sur_changes_for_developers#ARM64.2FAArch64.2FAppleSilicon_Support might be helpful for reference.

Willian-Zhang avatar Nov 21 '20 14:11 Willian-Zhang

@Willian-Zhang I don't think we have resource to work on it yet, we'll need some help to do that.

PeterDaveHello avatar Nov 21 '20 14:11 PeterDaveHello

XCode 12 has cross-compiling, so you can build for ARM on an x86 Mac. I'd be happy to test builds with my M1 Mac Mini.

thebitstick avatar Nov 23 '20 23:11 thebitstick

@thebitstick Thanks! Contributions are very welcome and needed here!

PeterDaveHello avatar Nov 24 '20 08:11 PeterDaveHello

And my axe! If there are clear enough setup guides I'd be happy to offer my resources, both machine and time wise

flying-sausages avatar Dec 15 '20 22:12 flying-sausages

I've managed to rebuild a couple apps like ffmpeg, mpv, and iina for arm64 before any official builds were released so I'd be more than willing to give this a go and do a little how-to writeup. This and Dropbox are the only x86 apps left that I use on a daily basis.

shermanikk avatar Jan 06 '21 17:01 shermanikk

I am completely inexperienced in such things, but if you need another tester and have a dmg or something I can surely also test it on my M1.

kellertuer avatar Jan 06 '21 17:01 kellertuer

Yeah I've got an M1 MBA myself, hence the motivation to do these pre-release arm64 builds. I won't be able to really put my head into it until later today but anything I find out will be posted here.

I am completely inexperienced in such things, but if you need another tester and have a dmg or something I can surely also test it on my M1.

shermanikk avatar Jan 06 '21 17:01 shermanikk

I don't know how to compile a project... But I have a Mac Mini M1 now and I really miss Transmission Remote GUI :) If I can help, I'll do !

zepretender avatar Jan 07 '21 09:01 zepretender

Well the old Transmission Remote GUI works fine on my M1 with Rosetta; just since it only respects dark mode half, it does not look nice.

kellertuer avatar Jan 07 '21 09:01 kellertuer

Well the old Transmission Remote GUI works fine on my M1 with Rosetta; just since it only respects dark mode half, it does not look nice.

How do you do ? Here, I can't launch it. It's "PowerPC/32bits", so it can't be launched

zepretender avatar Jan 07 '21 09:01 zepretender

Are you using 5.18? That is 64 bit I think? Also Homebrew might work https://formulae.brew.sh/cask/transmission-remote-gui

kellertuer avatar Jan 07 '21 09:01 kellertuer

Are you using 5.18? That is 64 bit I think? Also Homebrew might work https://formulae.brew.sh/cask/transmission-remote-gui

Yes, I've downloaded latest release (5.18). It doesn't launch. When I use iMobie M1 App Checker, it says that this release can't be launch on a M1.

For the homebrew... I'm to newbie to understand how to do :(

zepretender avatar Jan 07 '21 09:01 zepretender

@zepretender You might be encountering issues with the app not being signed. Go to your Applications folder, right-click on the app, and select Open. You'll only have to do this once.

valentine avatar Jan 11 '21 20:01 valentine

Screen Shot 2021-01-19 at 6 01 46 AM Okay, after a bunch of fiddling I have managed to successfully build transgui for aarch64. Hooray!

I even get it to launch, and it respects dark mode! Neat! Screen Shot 2021-01-19 at 6 33 51 AM

But when I try to connect to a transmission rpc interface I get this error: Screen Shot 2021-01-19 at 6 35 24 AM

I'm assuming this is because I wasn't supposed to edit line 787 of restranslator.pas which was giving me the compilation error:

transgui/restranslator.pas(787,24) Error: (3284) Operator is not overloaded: "Class Of TReader" and "Boolean"

so I blindly broke the if statement into two and it seemed to be happy with that, but clearly that is is not the correct solution.

begin if Sender is TReader and Assigned(TReader(Sender).Owner) then {if Assigned(TReader(Sender).Owner) then} OwnerName := TReader(Sender).Owner.GetNamePath;

this is literally my first time even looking at pascal code so I'm not quite sure what the issue is really. Assigned() is just supposed to check if there's a pointer for the given object, and return a boolean. I have a feeling this is one of those incredibly unhelpful compiler errors that is actually being caused by something else entirely, but at this point I'm stumped. Any ideas?

shermanikk avatar Jan 19 '21 14:01 shermanikk

Oh and I almost forgot, for anyone else who wants to join me in the mudpit, here's what I've had to do to get to this point:

  1. Build FPC from latest git source
  2. Build Lazarus from trunk
  3. Install openssl with homebrew
  4. Add to .fpc.cfg: -Fl/opt/homebrew/Cellar/[email protected]/1.1.1i/lib
  5. Edit transgui/synapse/source/lib/ssl_openssl_lib.pas:
@@ -113,8 +113,8 @@ const
		 var
		   {$IFNDEF MSWINDOWS}
		     {$IFDEF DARWIN}
		-    DLLSSLName: string = 'libssl.dylib';
		-    DLLUtilName: string = 'libcrypto.dylib';
		+    DLLSSLName: string = 'libssl.1.1.dylib';
		+    DLLUtilName: string = 'libcrypto.1.1.dylib';
		     {$ELSE}
		      {$IFDEF OS2}
		       {$IFDEF OS2GCC}
  1. Edit setup/macosx/create_app_new.sh:
                -lazdir="${1:-/Developer/lazarus/}"
		+lazdir="${1:-<your laz_trunk dir>}

		 if [ -z "${CI-}" ]; then
		   ./install_deps.sh
		@@ -24,11 +24,11 @@ fi
		 mkdir -p ../../Release/
		 sed -i.bak "s/'Version %s'/'Version %s Build $build'#13#10'Compiled by: $fpc_ver, Lazarus v$lazarus_ver'/" ../../about.lfm
		 
		-lazbuild -B ../../transgui.lpi --lazarusdir=/Developer/lazarus/ --compiler=/usr/local/bin/fpc --cpu=x86_64 --widgetset=cocoa
		+lazbuild -B ../../transgui.lpi --lazarusdir=<your laz_trunk dir> --compiler=/usr/local/bin/fpc --cpu=aarch64 --widgetset=cocoa
		 
		 # Building Intel version
		-make -j"$(sysctl -n hw.ncpu)" -C ../.. clean CPU_TARGET=x86_64 "$lazdir"
		-make -j"$(sysctl -n hw.ncpu)" -C ../.. CPU_TARGET=x86_64 "$lazdir"
		+make -j"$(sysctl -n hw.ncpu)" -C ../.. clean CPU_TARGET=aarch64 "$lazdir"
		+make -j"$(sysctl -n hw.ncpu)" -C ../.. CPU_TARGET=aarch64 "$lazdir" 
  1. Edit restranslator.pas
		   ResourceName: AnsiString;
		   OwnerName: AnsiString;
		 begin
		-  if Sender is TReader and Assigned(TReader(Sender).Owner) then
		-    OwnerName := TReader(Sender).Owner.GetNamePath;
		+  if Sender is TReader {and Assigned(TReader(Sender).Owner)} then
		+    if Assigned(TReader(Sender).Owner) then
		+      OwnerName := TReader(Sender).Owner.GetNamePath;
  1. cd setup/macosx
  2. bash create_app_new.sh
  3. *jeff goldblum voice* Step 10? There is no step 10!

shermanikk avatar Jan 19 '21 16:01 shermanikk

well what do you know, it works! I figured out the duplicate object member error was totally unrelated to my braindead fix in restranslator.pas, it was actually this same issue popping up again: https://github.com/transmission-remote-gui/transgui/issues/1325 and all I had to do was use the 1329 patch provided there! After fixing that, it seems to work fine! Tested by connected to my debian linux server running transmission-daemon 3.00. It's even proxied through nginx to give it SSL and that's working fine, no issues. Screen Shot 2021-01-28 at 11 37 07 AM Screen Shot 2021-01-28 at 11 37 48 AM Tried everything I could think of and it all seems to be working, doesn't crash or anything either. All is well, so someone on the official end of things can basically provide a real build of this with the instructions I've provided here and minimal effort. Screen Shot 2021-01-28 at 11 39 06 AM (ignore all the errored torrents, that is a completely unrelated zfs issue that just happened. fml. )

If anyone else wants to try out this arm64 build I made, feel free, but the usual caveats that I provide zero support for this build, make no promises it won't set your dog on fire, etc. use at your own risk! transgui-macosx-arm64.zip

shermanikk avatar Jan 28 '21 19:01 shermanikk

Thanks, this already looks quite great! (looking forward to finally being able to read marked lines in Dark mode). On my machine, sadly, your provided app can not be launched (the application is damaged and not be started is the error message)

kellertuer avatar Jan 28 '21 21:01 kellertuer

Thanks, this already looks quite great! (looking forward to finally being able to read marked lines in Dark mode). On my machine, sadly, your provided app can not be launched (the application is damaged and not be started is the error message)

Huh, I definitely signed it with my dev account so anyone should be able to run it. What happens when you try to run "Transmission Remote GUI.app/Contents/MacOS/transgui" directly? Sorry I'm kind of new to this and don't know what I'm doing at all, I'm just a blind man feeling his way in the dark here.

shermanikk avatar Jan 28 '21 21:01 shermanikk

No, sorry, I know what an unsigned application looks like and how to start it. I mean the app is broken like in: I can not open the container to access the binary you refer to.

kellertuer avatar Jan 28 '21 21:01 kellertuer

No, sorry, I know what an unsigned application looks like and how to start it. I mean the app is broken like in: I can not open the container to access the binary you refer to.

That's bizarre, it definitely had the proper structure when I zipped it, and I tried downloading the zip on another machine and it unzipped fine. Either way I signed the entire .app bundle and re-uploaded the zip, so try downloading it again.

shermanikk avatar Jan 28 '21 21:01 shermanikk

I still got a “signed by untrusted developer”, but that's easy and is only the first start, so that works! Nice! Finally a proper dark mode and a native app. Thanks!

kellertuer avatar Jan 28 '21 21:01 kellertuer

I still got a “signed by untrusted developer”, but that's easy and is only the first start, so that works! Nice! Finally a proper dark mode and a native app. Thanks!

Awesome, I guess that zip got messed up somehow when I uploaded it or something, weird. Glad it's working for others now, if I did all that work and nobody else could benefit it'd break my poor little nerd heart. Hooray!

shermanikk avatar Jan 28 '21 21:01 shermanikk

Works perfectly, thanks for working on this @shermanikk!

frankyw avatar Jan 28 '21 22:01 frankyw

Tested @shermanikk's build and it runs great. Great job!

thebitstick avatar Jan 28 '21 22:01 thebitstick

Great work @shermanikk - but I oddly get an error "Unable to load OpenSSL library files: libssl.1.1.dylib and libcrypto.1.1.dylib" after giving the app permissions. It sort of runs still but cannot connect to my Transmission Daemon running over SSL

jeromeof avatar Jan 28 '21 22:01 jeromeof

Great work @shermanikk - but I oddly get an error "Unable to load OpenSSL library files: libssl.1.1.dylib and libcrypto.1.1.dylib" after giving the app permissions. It sort of runs still but cannot connect to my Transmission Daemon running over SSL

Oh I guess they didn't get built-in, still new at this. All you need to do is install openssl with homebrew in /opt/homebrew. That's the location I used when building it so I'm assuming it will be looking for them there.

shermanikk avatar Jan 28 '21 23:01 shermanikk

Great work @shermanikk - but I oddly get an error "Unable to load OpenSSL library files: libssl.1.1.dylib and libcrypto.1.1.dylib" after giving the app permissions. It sort of runs still but cannot connect to my Transmission Daemon running over SSL

Oh I guess they didn't get built-in, still new at this. All you need to do is install openssl with homebrew in /opt/homebrew. That's the location I used when building it so I'm assuming it will be looking for them there.

Thank you for your fantastic work! I also encounter the openssl issue too... I tried to compile the code from scratch but now is blocked while linking transgui... The ld complains about

(9015) Linking ./transgui
ld: warning: building for macOS 10.5 is deprecated
ld: warning: passed two min versions (10.5, 11.0.0) for platform macOS. Using 11.0.0.
ld: library not found for -lc
An error occurred while linking
Error: (9013) Error while linking
Fatal: (10026) There were 1 errors compiling module, stopping
Fatal: (1018) Compilation aborted

Any ideas? I used the official fpc 3.2.2 for M1 and compiled Lazarus myself. Other configurations are following your instructions.

qinyongqiang avatar May 21 '21 09:05 qinyongqiang

Oh I guess they didn't get built-in, still new at this. All you need to do is install openssl with homebrew in /opt/homebrew. That's the location I used when building it so I'm assuming it will be looking for them there.

Which version were you using? Mine cannot be found. This is my install of OpenSSL via brew.

~ ❯❯❯ brew info openssl
[email protected]: stable 1.1.1k (bottled) [keg-only]
Cryptography and SSL/TLS Toolkit
https://openssl.org/
/opt/homebrew/Cellar/[email protected]/1.1.1k (8,071 files, 18MB)
  Poured from bottle on 2021-03-29 at 19:37:47
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/[email protected]
License: OpenSSL
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /opt/homebrew/etc/[email protected]/certs

and run
  /opt/homebrew/opt/[email protected]/bin/c_rehash

[email protected] is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides LibreSSL.

If you need to have [email protected] first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

For compilers to find [email protected] you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"

For pkg-config to find [email protected] you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig"

==> Analytics
install: 748,044 (30 days), 2,616,398 (90 days), 8,792,644 (365 days)
install-on-request: 55,366 (30 days), 240,031 (90 days), 1,126,038 (365 days)
build-error: 0 (30 days)

flying-sausages avatar May 21 '21 09:05 flying-sausages

Oh I guess they didn't get built-in, still new at this. All you need to do is install openssl with homebrew in /opt/homebrew. That's the location I used when building it so I'm assuming it will be looking for them there.

Which version were you using? Mine cannot be found. This is my install of OpenSSL via brew.

~ ❯❯❯ brew info openssl
[email protected]: stable 1.1.1k (bottled) [keg-only]
Cryptography and SSL/TLS Toolkit
https://openssl.org/
/opt/homebrew/Cellar/[email protected]/1.1.1k (8,071 files, 18MB)
  Poured from bottle on 2021-03-29 at 19:37:47
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/[email protected]
License: OpenSSL
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /opt/homebrew/etc/[email protected]/certs

and run
  /opt/homebrew/opt/[email protected]/bin/c_rehash

[email protected] is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides LibreSSL.

If you need to have [email protected] first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

For compilers to find [email protected] you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"

For pkg-config to find [email protected] you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig"

==> Analytics
install: 748,044 (30 days), 2,616,398 (90 days), 8,792,644 (365 days)
install-on-request: 55,366 (30 days), 240,031 (90 days), 1,126,038 (365 days)
build-error: 0 (30 days)

Seems like same to yours. (except the brew source)

$ brew info openssl
[email protected]: stable 1.1.1k (bottled) [keg-only]
Cryptography and SSL/TLS Toolkit
https://openssl.org/
/opt/homebrew/Cellar/[email protected]/1.1.1k (8,071 files, 18MB)
  Poured from bottle on 2021-05-21 at 14:34:05
From: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git/Formula/[email protected]
License: OpenSSL
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /opt/homebrew/etc/[email protected]/certs

and run
  /opt/homebrew/opt/[email protected]/bin/c_rehash

[email protected] is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides LibreSSL.

If you need to have [email protected] first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

For compilers to find [email protected] you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"

For pkg-config to find [email protected] you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig"

==> Analytics
install: 748,044 (30 days), 2,616,398 (90 days), 8,792,644 (365 days)
install-on-request: 55,366 (30 days), 240,031 (90 days), 1,126,038 (365 days)
build-error: 0 (30 days)

qinyongqiang avatar May 21 '21 10:05 qinyongqiang