Lazarus

Programming => Widgetset => Cocoa => Topic started by: ChrisR on July 07, 2020, 08:37:17 pm

Title: Apple Developer Transition Kit
Post by: ChrisR on July 07, 2020, 08:37:17 pm
Today I received an Apple DTK. I tried out the following Lazarus applications compiled for Intel x86-64:
 MRIcroGL OpenGL Volume Rendering, PascalScript, PythonEngine https://github.com/neurolabusc/MRIcroGL
 Surfice OpenGL Suface Rendering, PythonEngine https://github.com/neurolabusc/surf-ice/releases
 Several Metal Projects https://github.com/neurolabusc/Metal-Demos
 Lazarus IDE

In general, they all seem fine. Despite being deprecated, OpenGL works very nicely. MacOS 11.0 Beta still comes with Python 2.7 installed (despite 2.7 being past "end of life").

The performance of the OpenGL graphics is really just fine. Since my desktop is a 1920x1080 while my MacBook is a retina 2560x1600, this may not be a fair comparison. However, the performance of the Lazarus built x86-64 tools seems pretty seamless and completely usable.

The big issue I have encountered is that I can not install the Xcode command line tools. Running "xcode-select --install" from the command line brings up the standard "Finding software" window, but after a few hours it has not finished. I will try updating all system software and restarting. Without the SDKs installed by this tool, I can not compile Lazarus or FPC projects on the DTK.

So long story short, looks like Intel-compiled Lazarus projects work just fine on Apple Silicon. Hopefully Jonas and Dmitry can get fps and Lazarus compiling locally in short order.

Title: Re: Apple Developer Transition Kit
Post by: jwdietrich on July 07, 2020, 08:59:55 pm
The big issue I have encountered is that I can not install the Xcode command line tools. Running "xcode-select --install" from the command line brings up the standard "Finding software" window, but after a few hours it has not finished. I will try updating all system software and restarting. Without the SDKs installed by this tool, I can not compile Lazarus or FPC projects on the DTK.

If this continues to be unsuccessful you might want to submit a bug report at https://developer.apple.com/bug-reporting/ (https://developer.apple.com/bug-reporting/) or ask for help at https://developer.apple.com/forums (https://developer.apple.com/forums). And did you know that Apple asks for feedback in the annual developer survey (https://developer.apple.com/app-store/tell-us/)? This may be another place to ask for support for Free Pascal.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on July 07, 2020, 09:01:57 pm
I had the same issue with installing the command line tools on macOS 11.0 beta on my Intel Mac. As a workaround, you can point FPC to the command line tools embedded in the Xcode application bundle using the -FD command line parameter, e.g. -FD/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/
Title: Re: Apple Developer Transition Kit
Post by: ChrisR on July 07, 2020, 10:36:29 pm
@jwdietrich I did post a topic, but it was removed from the web site as it relates to beta software. I have now learned that the expected behavior for beta software is to report with the feedback assistant. The license is pretty strict, and I can not post benchmarks, and the lack of open communication makes it hard to see how others have handled these issues. Regardless, it is their software and hardware, and I agreed to abide by them.
Title: Re: Apple Developer Transition Kit
Post by: trev on July 08, 2020, 02:14:34 am
And did you know that Apple asks for feedback in the annual developer survey (https://developer.apple.com/app-store/tell-us/)? This may be another place to ask for support for Free Pascal.

Despite being a paid-up "Apple developer" I did not know about the survey, so thanks! I have filled it in pointing out that I do not use Xcode but FPC and Lazarus and asking for specific FPC support such as the translation of framework API headers and code samples :) I doubt my single contribution will have much effect, but if everyone using FPC/Lazarus filled in the survey ...
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 08, 2020, 07:55:06 pm
Hi Chris,

Thanks for the good news! It's nice to hear that good performance of x86-64 OpenGL/Metal apps in emulation on ARM.

I hope to see Lazarus on Mac ARM in future.

Good luck for Lazarus/FPC team!
Title: Re: Apple Developer Transition Kit
Post by: Manlio on July 09, 2020, 01:12:49 pm
Hi Chris,

[...] good performance of x86-64 OpenGL/Metal apps in emulation on ARM. [...]


Does anyone know -- or have any sense in this regard -- whether old (intel-era) apps will continue to work on ARM (via emulation or whatever) or will they be deprecated at some point, and then stop working?
Title: Re: Apple Developer Transition Kit
Post by: PascalDragon on July 09, 2020, 01:24:58 pm
With Apple you can't tell for sure whether they'll continue to work. E.g. when they transitioned from PowerPC to Intel they only shipped Rosetta from 10.4.4 till 10.6.8. For Rosetta 2... time will tell.

But if I had to guess in two or three years that will be thrown out. They'll merely give the developers enough time to port their software and then it's goodbye Intel.
Title: Re: Apple Developer Transition Kit
Post by: trev on July 09, 2020, 02:01:50 pm
It was six years from the appearance of the first Intel in the Mac Transition Kit in June 2005 until Apple dropped Rosetta for Lion in July 2011.

During the current transition from Intel to ARM, Apple said they would still be releasing new Macs with Intel processors, so who knows how long it'll be before Rosetta 2 gets axed from a new OS release.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 17, 2020, 03:28:08 pm
I also received Apple Developer Transition Kit today.

My Metal app has big visual problems. Textures appear at wrong coordinates on the screen.

Same app on Big Sur + Intel iMac works fine.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on July 17, 2020, 06:06:37 pm
While a compiler bug is if course possible, it sounds more like an error in your program. One thing that immediately springs to mind is the fact that on AppleSilicon, the page size (and hence page alignment) is 16KB, as opposed to 4KB on Intel. I have zero experience programming Metal, but given the integration of the GPU and the ARM64 chip, it wouldn't surprise me if that were a requirement for both. There should also be a validation mode that you can activate for Metal to find errors (although I don't know if it will catch this one).
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 17, 2020, 08:46:33 pm
Jonas,

Thanks for your advice! I only tested Intel version of my app on Apple Silicon. When I begin compilation of ARM version, I'll read again your message.

It seems that problems in my Metal app on Apple Silicon are related with wrong matrix computations.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on July 17, 2020, 08:54:47 pm
Then it may be bug in Rosetta 2. Intel applications should work identical without any changes on the DTK (and the final versions of the AArch64 Macs). Everything from the Intel architecture, from floating point behaviour to page size, should be emulated completely by Rosetta 2. See https://developer.apple.com/videos/play/wwdc2020/10214/ for more details
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 19, 2020, 09:49:11 pm
Can someone post info how to install FPC and Lazarus on Apple DTK?

I have problems with installing all tools.

1. As Chris wrote above, Command Line Tools cannot be installed, it freezes forever on "Finding software" window.

2. I can't install SVN. Because brew is not installed by default. I tried to manually download brew and install it, but it doesn't work correctly.
Another option - MacPorts says that my macOS is not Catalina and exits.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on July 19, 2020, 09:59:27 pm
Can someone post info how to install FPC and Lazarus on Apple DTK?

I have problems with installing all tools.

1. As Chris wrote above, Command Line Tools cannot be installed, it freezes forever on "Finding software" window.
See the installation instructions I lined at https://forum.lazarus.freepascal.org/index.php/topic,50187.msg369996.html#msg369996, including the warnings near the bottom.

Quote
2. I can't install SVN. Because brew is not installed by default. I tried to manually download brew and install it, but it doesn't work correctly.
Another option - MacPorts says that my macOS is not Catalina and exits.
The easiest option is to use the git mirror: https://github.com/graemeg/freepascal
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 19, 2020, 10:18:17 pm
Jonas,

Thanks, I'll try again. It looks a bit complicated at this stage.

BTW, when I waited for "Finding software", I opened System Preferences > Updates and Mac suggested me install Command Line Tools Beta 2. It was downloaded and installed successfully. But I'm not sure that was installed correctly.
Title: Re: Apple Developer Transition Kit
Post by: skalogryz on July 20, 2020, 04:27:49 am
2. I can't install SVN. Because brew is not installed by default. I tried to manually download brew and install it, but it doesn't work correctly.
Another option - MacPorts says that my macOS is not Catalina and exits.
you can try to copy over svn binaries (executable and dependency libs) intel build from 10.15 (or any other macOS version)

Rosetta does its job nicely.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 21, 2020, 08:31:51 am
Dmitry,

Thanks! I'll try this today.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 21, 2020, 11:02:28 am
Did you install Xcode 12 beta 2
or Xcode 12 for macOS Universal Apps beta 2 ?

When I run this command:

make distclean

I get the following error:

Quote
igor@Igors-Mac fpcsrc % make distclean
xcrun: error: unable to load libxcrun (dlopen(/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib, 0x0005): could not use '/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib' because it is not a compatible arch).
igor@Igors-Mac fpcsrc %
Title: Re: Apple Developer Transition Kit
Post by: ChrisR on July 21, 2020, 11:37:02 am
Igor-

I made this mistake as well, and Jonas provided the solution:

---

It's because you installed those manually downloaded command line tools. They only contain x86-64 code, and the command line tools inside the Xcode-beta app are trying to load libraries from them.

You can try switching them over back to the ones in the Xcode-beta.app with
 sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer/

Also, when doing a make install after building, add
FPC=$PWD/compiler/ppca64

to the make install command line (along with the OPT="-FD.. -XR..") to ensure a native aarch64 compiler gets installed rather than an x86-64 cross compiler.

----

Once you have compiled fpc, you can set up your ~/.fpc.cfg so you do not have to include the FD and XR arguments, as described here:

https://wiki.freepascal.org/macOS_Big_Sur_changes_for_developers#ARM64.2FAArch64.2FAppleSilicon_Support
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 21, 2020, 11:55:14 am
Thanks, Chris!

I did that you suggested, and it seems to solved the problem.

Now I'm performing steps suggested by Jonas.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 21, 2020, 12:00:31 pm
Chris,

Can you also tell how you installed Lazarus?
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 21, 2020, 03:00:55 pm
I compiled Lazarus Trunk as described in Wiki (https://wiki.freepascal.org/Installing_Lazarus_on_macOS#Lazarus_Trunk)

When I try to run it:

Quote from: pascal
open startlazarus.app --args "--pcp=~/.laz_trunk"

I get the following error:

Quote
LSOpenURLsWithRole() failed with error -10810 for the file /Users/igor/WnSoft/Development/lazarus/startlazarus.app.
Title: Re: Apple Developer Transition Kit
Post by: skalogryz on July 21, 2020, 03:19:03 pm
apparently the "startlazarus" or "lazarus" files are missing execute right
https://apple.stackexchange.com/questions/181026/lsopenurlswithrole-failed-with-error-10810-cant-open-install-os-x-yosemite

you can set the right via command line or via Finder file properties
Title: Re: Apple Developer Transition Kit
Post by: ChrisR on July 21, 2020, 03:32:26 pm
After following Jonas' fpc guide
 https://wiki.freepascal.org/macOS_Big_Sur_changes_for_developers#ARM64.2FAArch64.2FAppleSilicon_Support

I downloaded the svn trunk of Lazarus and ran "make bigide" in the Lazarus folder. The "Lazarus.app" was created that I can run from the finder and put on my dock. If you do follow the page you link, remember to use CPU_TARGET=aarch64 rather than CPU_TARGET=x86_64, but it seems like Cocoa and the aarch64 are chosen implicitly if you do not specify them.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 21, 2020, 04:21:03 pm
skalogryz,

I used chmod 755 for lazarus and startlazarus

then I get again this error if I call in Terminal:

open startlazarus.app --args "--pcp=~/.laz_trunk"

Quote
igor@Igors-Mac lazarus % open startlazarus.app --args "--pcp=~/.laz_trunk"
LSOpenURLsWithRole() failed with error -10810 for the file /Users/igor/WnSoft/Development/lazarus/startlazarus.app.

If I run lazarus.app in Finder I get -1 error.

But If I run:
./lazarus
It starts and works.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 21, 2020, 04:23:22 pm
Chris, how you installed svn? Can you explain in more details?
I have no problem with installing svn on traditional Mac, not on this Apple DTK.
Title: Re: Apple Developer Transition Kit
Post by: ChrisR on July 21, 2020, 07:53:02 pm
The DTK comes with git, so the easiest solution is to just get the latest svn from github
  https://github.com/graemeg/lazarus
Dmitry helped me install svn software on my DTK, so I am not sure the method he used. So for my system I can just run svn, but for other users git clone is an easier solution that should work the same.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 21, 2020, 08:44:36 pm
Regrettably Lazarus from Trunk works wrong on this Apple DTK.

1. I downloaded again Lazarus trunk from Git (manually from website).

2. "make bigide" (or "make LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide")

3. chmod +x lazarus, chmod +x startlazarus

4. I can run only ./lazarus from /lazarus.app/Contents/MacOS/

Click on Lazarus.app in Finder shows error -1

startlazarus.app (or ./startlazarus) shows an error:

Quote
LSOpenURLsWithRole() failed with error -10810 for the file /Users/igor/WnSoft/Development/lazarus/startlazarus.app.
Title: Re: Apple Developer Transition Kit
Post by: ChrisR on July 21, 2020, 09:53:55 pm
Igor,
 I can not replicate your issue, as I can launch my copies of Lazarus either from the command line or clicking on the "startlazarus" or "Lazarus.app" icons in the finder.

However, with this version of MacOS, it is clear that clicking an icon from the finder has different privileges than running the same application from the terminal. Here is what I have observed when clicking in the finder that does not happen when running in the terminal:
 1. The app will receive an argument with a unique process serial number, e.g. "-psn_0_989382", so if a Pascal program uses ParamStr(), it needs to ignore this.
 2. The app will refuse to open any file that has the executable bit set on. Perhaps git clone is copying some files with this bit on. You could check this for your files (e.g. 'ls -l ~/.fpc.cfg' and switch this bit off 'chmod -x ~/.fpc.cfg')
 3. The app will refuse to open any files that are not within its sandbox.  The files that are permitted to be opened can change when the application is recompiled, as the OS seems to decide the user has not explicitly provided access to the file. I found this really tricky, as I have a most-recently-used menu item that allows the user to quickly open recently seen files. If the app is rebuilt, the FileExists() function reports the file exists, the fpAccess() function does not give sensible information, and the FileSize reports the correct file size even though the user does not have read access.

I would propose that fpAccess should be updated for recent MacOS versions (sounds like a Dmitry's expertise) so R_OK correctly reflects if the user can open a file. Additionally, it might be nice to have the pascal file reading routines give a meaningful message if the file is outside the sandbox. Troubleshooting these routines is a bit of a pain, as trusted applications work fine, but the same application works differently when run from the finder.

My brute-force method to find out if the executable has permission to read a file is to read the first byte from the file. A try..except block keeps the program from crashing.

function IsReadable(fnm: string): boolean;
label 222;
var
  f: file;
  b: byte;
begin
  result := false;
  if not fileexists(fnm) then goto 222;
  if FSize(fnm) < 2 then goto 222;
  AssignFile(f, fnm);
  {$I+}
  try
    FileMode := fmOpenRead;  //Set file access to read only
    Reset(f, 1);
    if ioresult <> 0 then
       exit;
    b := 0;
    BlockRead(f, b, sizeof(b)); //Byte-order Identifier
    CloseFile(f);
    result := true;
  except
    result := false;
  end;
  222:
  if result then exit;
  printf('Unable to read file (not in sandbox?): '+fnm);
end;
Title: Re: Apple Developer Transition Kit
Post by: ChrisR on July 21, 2020, 10:09:40 pm
Igor,
 To test my hypothesis, see if turning on "Full Disk Access" for your "Lazarus" fixes your issue:
   https://benscheirman.com/2019/10/troubleshooting-appkit-file-permissions/
(not sure if this helps if the executable bit of files is switched on, but should help other files).
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 21, 2020, 10:51:10 pm
Chris,

I'm grateful for your advices. I'll check tomorrow.

I found a similar problem with launching of compiled apps. And I found a solution. My project sources were copied from another Mac in a ZIP. Of course, I rebuilt executable file and recreated APP bundle. But I've got exactly same error code. I deleted manually APP bundle and executable, and re-created them again. Now this APP runs correctly. It seems that macOS couldn't overwrite old executable and bundle files created on another Mac.

Does LLDB debugger work on your Apple DTK? When I run the debugger the icon of the debugger on the top toolbar in Lazarus disappears and nothing happens.

Also I couldn't set a global environment variable in /Library/LaunchAgents in a plist file. It worked fine in Catalina on x86-64 Mac. Apple DTK doesn't load custom plist with my global variable.
Title: Re: Apple Developer Transition Kit
Post by: trev on July 22, 2020, 07:14:27 am
To test my hypothesis, see if turning on "Full Disk Access" for your "Lazarus" fixes your issue:
   https://benscheirman.com/2019/10/troubleshooting-appkit-file-permissions/
(not sure if this helps if the executable bit of files is switched on, but should help other files).

In Beta1 (Intel) this did not help and I had to move the project out of the Documents folder. However, in Beta2 (Intel) the lazarus executable was already listed in the Full Disk Access list and enabling it via the checkbox resolved the issue for me.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 22, 2020, 08:01:13 am
I solved the problem with Lazarus. I deleted a link in MacOS and copied Lazarus executable to MacOS folder of Lazarus bundle. Now it works fine.

I still can't install svn. MacPorts is not available for Big Sur. brew installed incorrectly.
I tried to manually from svn executables from /usr/bin/ on my another Mac, but this file copy operation is not permited:
sudo cp svn /usr/bin
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 22, 2020, 08:23:00 am
Lazarus from Trunk doesn't include any debugger. Tools > Settings > Debuggers shows nothing. There is no a drop down combobox with a list of available debuggers.

I tried to install manually lazdebuggerfplldh.lpk and recompile Lazarus. Nothing appeared in Debuggers list.
Title: Re: Apple Developer Transition Kit
Post by: trev on July 22, 2020, 08:56:31 am
I still can't install svn. MacPorts is not available for Big Sur. brew installed incorrectly.
I tried to manually from svn executables from /usr/bin/ on my another Mac, but this file copy operation is not permited:
sudo cp svn /usr/bin

Have you tried "xcrun svn" ?
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 22, 2020, 08:59:32 am
Quote
igor@Igors-Mac ~ % xcrun svn
xcrun: error: sh -c '/Applications/Xcode-beta.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find svn 2> /dev/null' failed with exit code 17664: (null) (errno=No such file or directory)
xcrun: error: The subversion command line tools are no longer provided by Xcode.
igor@Igors-Mac ~ %
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on July 22, 2020, 11:02:09 am
I solved the problem with Lazarus. I deleted a link in MacOS and copied Lazarus executable to MacOS folder of Lazarus bundle. Now it works fine.

I still can't install svn. MacPorts is not available for Big Sur. brew installed incorrectly.
I tried to manually from svn executables from /usr/bin/ on my another Mac, but this file copy operation is not permited:
sudo cp svn /usr/bin

/usr/bin has been read-only since OS X 10.11 due to SIP (system integrity protection). You can copy it to /usr/local/bin instead, but you will also have to copy the libraries that it links to to /usr/local/lib (you can see them with "otool -L" iirc).
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 22, 2020, 02:13:26 pm
Thanks, Jonas
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 22, 2020, 03:57:54 pm
I tested the same LCL project which loads large JPEG image on Windows PC with Intel Core i5, iMac 21.5 4K Retina with Core i5 and on Apple DTK (x86-64 compiled version and native AARCH64 version).

Performance of A12Z CPU is great. Even in Rosetta 2 emulation.
I can't publish exact values due to NDA, but I'm sure that new Macbook and iMac with ARM will be very fast for old and new apps.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 22, 2020, 07:59:31 pm
Good news.

1. I finally compiled my app natively for ARM64. And it works!

2. Bugs in Metal 3D appear when I use O2 code optimizations. It seems that my code has some mistake with Metal calculations. I think that we'll fix it later.

3. I found LLDB debugger in Lazarus Trunk on Apple DTK.

Thanks for FPC/Lazarus team for their great work on FPC AARCH64!
Title: Re: Apple Developer Transition Kit
Post by: ChrisR on July 22, 2020, 09:25:45 pm
Igor,
  If you want to compile with code optimization, make sure you recompile fpc so that you have svn  45823, as two bugs were closed in the last two days:
  https://bugs.freepascal.org/view.php?id=37397
  https://bugs.freepascal.org/view.php?id=37393
With these latest commits, the whole IDE compiles with -O3. Hopefully, this will resolve your issue, if not it would be good to isolate the compiler issue and post a bug report. At the moment, all my Lazarus projects appear to compile and operate correctly, including all my Metal demos.

Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 23, 2020, 03:32:00 pm
Chris,

Thanks, I downloaded the latest FPC + Lazarus. It didn't fix my problems, probably mistake in my code.

By the way, I found exact reason of the problem with launching of Lazarus after compilation:

Quote
LSOpenURLsWithRole() failed with error -10810 for the file /Users/igor/WnSoft/Development/lazarus/startlazarus.app.

This problem occured if I create a folder for Lazarus in external file manager (Commander One Pro) downloaded from App Store.

I started from a scratch and did all in Terminal/zsh. And now downloaded from Git and compiled Lazarus starts fine.

It seems that macOS doesn't trust to any executable files placed in a folder created in an app from App Store (sandboxed).
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 23, 2020, 10:10:49 pm
Is it possible to create Universal Binary with FPC now?

Does this technology mean that APP bundle will have doubled file size?
Title: Re: Apple Developer Transition Kit
Post by: mischi on July 23, 2020, 11:10:46 pm
Is it possible to create Universal Binary with FPC now?

Do this technology mean that APP bundle will have doubled file size?
Use the command "lipo" to create universal binaries from individually created binaries. The size of the universal binary will be more or less doubled. But if your app bundle has lots of resources like images, the total size will not increase a lot.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 24, 2020, 08:46:21 am
Use the command "lipo" to create universal binaries from individually created binaries. The size of the universal binary will be more or less doubled. But if your app bundle has lots of resources like images, the total size will not increase a lot.

Thanks! It works fine:
Code: Pascal  [Select][+][-]
  1. lipo -create -output universal_app x86_app arm_app

lipo command simply doubles file size of universal executable.

Universal binary solution is great for games where executable files are small part of total file size of a game. In my app 90% of files are executables and dylibs. It means that final product will be 40 MB instead of 20 MB.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 24, 2020, 09:42:32 am
I have a problem with setting Dark mode for a title of NSWindow. It works fine on Intel Mac.

And crashes on Apple DTK on this line:

Code: Pascal  [Select][+][-]
  1.   apr := objc_msgSend(cls, ObjCSelector('appearanceNamed:'), NSSTR(@ap[1]));

Code: Pascal  [Select][+][-]
  1. const
  2.   macOSNSAppearanceNameAqua = 'NSAppearanceNameAqua';
  3.   DefaultAppearance = macOSNSAppearanceNameAqua;
  4.   macOSNSAppearanceNameVibrantDark = 'NSAppearanceNameVibrantDark';
  5.   macOSNSAppearanceNameVibrantLight = 'NSAppearanceNameVibrantLight';
  6.  
  7. function UpdateAppearance(win: NSWindow; const AAppearance: String): Boolean;
  8. var
  9.   cls : id;
  10.   ap  : string;
  11.   apr : id;
  12. begin
  13.   Result := false;
  14.  
  15.   if not Assigned(win) then Exit;
  16.  
  17.   if AAppearance = ''
  18.     then ap := DefaultAppearance
  19.     else ap := AAppearance;
  20.  
  21.   cls := NSClassFromString( NSSTR('NSAppearance'));
  22.   if not Assigned(cls) then Exit; // not suppored in OSX version
  23.  
  24.   apr := objc_msgSend(cls, ObjCSelector('appearanceNamed:'), NSSTR(@ap[1]));
  25.   if not Assigned(apr) then Exit;
  26.  
  27.   if win.respondsToSelector(ObjCSelector('setAppearance:')) then
  28.   begin
  29.     objc_msgSend(win, ObjCSelector('setAppearance:'), apr);
  30.     Result := true;
  31.   end;
  32. end;
  33.  
Title: Re: Apple Developer Transition Kit
Post by: ChrisR on July 24, 2020, 01:04:11 pm
Igor, I have reported the Dark mode issue
  https://bugs.freepascal.org/view.php?id=37402
Presumably the naming has changed, and now the theme is expected to be system wide.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 24, 2020, 07:05:34 pm
Chris,

Thanks! I hope it will be fixed now.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on July 24, 2020, 07:56:06 pm
I have a problem with setting Dark mode for a title of NSWindow. It works fine on Intel Mac.

And crashes on Apple DTK on this line:

Code: Pascal  [Select][+][-]
  1.   apr := objc_msgSend(cls, ObjCSelector('appearanceNamed:'), NSSTR(@ap[1]));

Your code is invalid on all platforms, even if it will not crash everywhere. Please use Objective-Pascal to interface with Objective-C frameworks unless you know all of the implementation details of the Objective-C runtime. In the above case case: you must typecast objc_msgSend to the signature of the function you are calling, rather than use it's declared signature (which uses varargs).
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 25, 2020, 06:51:10 pm
Your code is invalid on all platforms, even if it will not crash everywhere. Please use Objective-Pascal to interface with Objective-C frameworks unless you know all of the implementation details of the Objective-C runtime. In the above case case: you must typecast objc_msgSend to the signature of the function you are calling, rather than use it's declared signature (which uses varargs).

Jonas,

I used a code from skalogryz from here:

https://github.com/skalogryz/macosext/blob/master/macosformprop.pas

I simply need to set Dark mode for a title of NSWindow.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 27, 2020, 01:34:27 pm
Igor, I have reported the Dark mode issue
  https://bugs.freepascal.org/view.php?id=37402
Presumably the naming has changed, and now the theme is expected to be system wide.

Chris,

I received a reply from skalogryz. It necessary to use a new version of the code from
https://github.com/skalogryz/macosext/blob/master/macosformprop.pas

It solves the problem with a title of NSWindow on ARM Mac. I already checked a test app.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 27, 2020, 03:56:44 pm
Can you suggest any ideas how to find a code which cause this error during compilation:

Quote
Error: /Users/igor/TestCode/project1/lib/aarch64-darwin/SysPng.s:6347:7: error: invalid operand for instruction
SysPng.pas(5470,0) Error: Error while assembling exitcode 1

This error occurs only with code optimization O2 or higher in Lazarus/FPC Trunk on Apple DTK.

Lazarus doesn't show where exactly this error occurs. SysPNG.pas is our old module.
Title: Re: Apple Developer Transition Kit
Post by: ChrisR on July 27, 2020, 05:22:34 pm
Igor,

It is hard to provide any guidance without seeing the source code of SysPng.pas. You might want to see if this is specific to Aarch64, or is seen in the FPC trunk for any architecture (I use FPC 3.2 on x86-64, but for Aarch64 we need to use FPC trunk). Next, I would suggest you try to develop a minimal program that elicits this bug and then make a bug report. Here are an example of two bugs I identified when using higher optimization levels:

  https://bugs.freepascal.org/view.php?id=37397
  https://bugs.freepascal.org/view.php?id=37393

Once I was able to provide concise bug reports, the compiler team was able to resolve them in less than a day.

The trick is isolating the bug. A good example is my issue 0037393, where the faulty procedure returned incorrect values but did not cause a crash - the crash happened much later. It did take a while to work out the root cause of the error. However, since both your code and my code works at lower optimization levels, you can ping-pong between optimization levels to work out the root error.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on July 27, 2020, 07:30:10 pm
Compile with -al, then the source code gets inserted as comments in the assembly code. That way you can see for which source line the invalid assembly was generated.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 28, 2020, 07:13:36 pm
Thanks for your advices!

Jonas,

Option -al was very helpful. I found exact code line which caused that problem. Probably it's a bug in FPC compiler for AARCH64. I'll write a simple test project tomorrow to check it.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 29, 2020, 09:55:18 am
Jonas,

I submited a bug-report for FPC Trunk. My code doesn't compile for AARCH64 with O2+ code optimization:

https://bugs.freepascal.org/view.php?id=37443
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on July 29, 2020, 09:56:25 pm
I think it's the same issue that caused https://bugs.freepascal.org/view.php?id=37427 . So if you update, it's probably already fixed.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 30, 2020, 09:50:10 am
Jonas,

I confirm that latest SVN version fixed the compilation problem on Apple Silicon.

P.S. Even the latest Lazarus Trunk always crashes on Apple Silicon when I call "Clean Up and Build" for any project:

Crashed Thread:        0  Dispatch queue: com.apple.main-thread
Exception Type:        EXC_BAD_ACCESS (SIGABRT)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Should I report a bug?
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on July 30, 2020, 10:07:55 pm
I submited a bug report:

https://bugs.freepascal.org/view.php?id=37453
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on August 09, 2020, 03:05:33 pm
Chris,

Did you manage to update macOS to Beta 4? I see a notification, but downloading fails in several seconds.
Title: Re: Apple Developer Transition Kit
Post by: trev on August 09, 2020, 03:35:04 pm
Assuming it's the same as the Intel version - software update offers two versions: Full (12GB) and (click on More...) and you get Update (3GB). I chose update :)
Title: Re: Apple Developer Transition Kit
Post by: ChrisR on August 09, 2020, 05:08:45 pm
Igor,
 I believe if you look at the left panel of the Software Update window you will see the text "Updates for this Mac are managed externally". If you see this, I believe that the "Update Now" button (if displayed) will not be functional. You need to wait for the external management system to push an update for you.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on August 10, 2020, 08:34:43 pm
Chris,

Thanks, I've understood.

trev,

I think it's a special case with this Apple DTK.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on August 10, 2020, 08:37:12 pm
It seems that macOS Big Sur for Apple Silicon doesn't support OpenAl (or it's a bug in current Beta).

My OpenAl code doesn't play anything. I found OpenALSoundManager here on the forum:
https://forum.lazarus.freepascal.org/index.php?topic=37890.0
and that code also doesn't play anything. Just silence.

APP compiled for Intel in Rosetta 2 emaulation plays OpenAl audio.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on August 10, 2020, 08:45:12 pm
If it didn't support OpenAL at all, you would get linker errors (or perhaps segmentation faults in case it's dynamically loaded, does not exist, and then you try to call its functions). It could also be a bug in the binding or in the way it links to/tries to load the framework.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on August 11, 2020, 09:59:47 am
Yes, it's logical.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on August 18, 2020, 09:04:12 pm
I had to restore Apple DTK Mac and reinstall FPC and Lazarus from trunk.

I successfully compiled FPC trunk for AARCH64.

But Lazarus trunk cannot be compiled:

Quote
page.inc(36,29) Error: Operator is not overloaded: "Class Of TNotebook" and "Boolean"
shape.inc(33,24) Error: Illegal expression
shape.inc(33,44) Error: Illegal expression
shape.inc(34,24) Error: Illegal expression
shape.inc(34,44) Error: Illegal expression
shape.inc(35,24) Error: Illegal expression
shape.inc(35,44) Error: Illegal expression
shape.inc(36,24) Error: Illegal expression
shape.inc(36,44) Error: Illegal expression
shape.inc(37,24) Error: Illegal expression
shape.inc(37,44) Error: Illegal expression
shape.inc(40,24) Error: Illegal expression
shape.inc(40,44) Error: Illegal expression
shape.inc(41,24) Error: Illegal expression
shape.inc(41,44) Error: Illegal expression
shape.inc(42,24) Error: Illegal expression
shape.inc(42,44) Error: Illegal expression
shape.inc(43,24) Error: Illegal expression
shape.inc(43,44) Error: Illegal expression
shape.inc(44,24) Error: Illegal expression
shape.inc(44,44) Error: Illegal expression
shape.inc(47,24) Error: Illegal expression
shape.inc(47,44) Error: Illegal expression
shape.inc(48,24) Error: Illegal expression
shape.inc(48,44) Error: Illegal expression
shape.inc(49,24) Error: Illegal expression
shape.inc(49,44) Error: Illegal expression
shape.inc(50,24) Error: Illegal expression
shape.inc(50,44) Error: Illegal expression
shape.inc(51,24) Error: Illegal expression
shape.inc(51,44) Error: Illegal expression
shape.inc(54,24) Error: Illegal expression
shape.inc(54,44) Error: Illegal expression
shape.inc(55,24) Error: Illegal expression
shape.inc(55,44) Error: Illegal expression
shape.inc(56,24) Error: Illegal expression
shape.inc(56,44) Error: Illegal expression
shape.inc(57,24) Error: Illegal expression
shape.inc(57,44) Error: Illegal expression
shape.inc(58,24) Error: Illegal expression
shape.inc(58,44) Error: Illegal expression
extctrls.pp(1726) Fatal: There were 41 errors compiling module, stopping
Fatal: Compilation aborted
make[1]: *** [alllclunits.ppu] Error 1
make: *** [lazbuild] Error 2

I've downloaded Lazarus trunk from git:

git clone https://github.com/graemeg/lazarus
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on August 18, 2020, 09:22:46 pm
UPD. I downloaded old revision from July 31 which worked fine for macOS ARM. Now Lazarus compiles OK on Apple DTK.

There is a bug in one of recent changes in the code.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on August 22, 2020, 08:41:53 am
Be careful with updating Apple DTK from Beta 1 to Beta 4 or 5. It falls to infinite bootloop. There are many complaints on Apple forum.

I had to restore my Apple DTK in DFU mode using another Mac and USB-C cable to recover macOS and install Beta 4 from a scratch.

Updating from Beta 4 to Beta 5 worked fine.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on September 18, 2020, 02:58:45 pm
Chris,

Can you check Beta 7 on Apple DTK?

I just updated from Beta 6 to Beta 7.

I could run earlier compiled ARM version of my app. After recompilation it crashes on startup.

Also since Beta 6 I can't load any dylibs which I compiled earlier on the same Mac (DTK).

It seems to work worse with each Beta.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on September 18, 2020, 07:02:39 pm
The issue with your dylibs no longer working under beta 6 is probably because they added a requirement for all binaries (executables and dylibs) to be code signed in that version. When you link an exe/library, the linker will add a fake code signature (that will be trusted by you local system, but not usable for distribution). That signature will be invalidated if you perform any extra operations on the generated binary afterwards though, in particular using the strip tool. And while FPC uses the linker's symbol stripping functionality when generating executables, it uses the strip tool when generating dynamic libraries (I think this is because older versions of the linker stripped too many symbols away).

So it should work if you codesign your libraries again after stripping them, either using a fake signature (see the beta 6 release notes for the command) or using a real code signing certificate. I'll look into changing the compiler as well. I'll also look into beta 7 issues (I did get a DTK in the end about two weeks ago).

Edit: to disable stripping, compile with -Xs-. That should allow your dylibs to work again.
Edit 2: it's actually listed as a known bug that strip invalidates these signatures, so I'll wait with making changes to the compiler since that suggests Apple may still fix it
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on September 19, 2020, 08:15:56 am
Jonas,

Thanks! I'll check on Monday again.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on September 19, 2020, 01:04:15 pm
There are actually a bunch of threads on Apple's forums about issues with codesigning on beta 7, e.g. https://developer.apple.com/forums/thread/660812 . My DTK (fortunately, in hindsight) failed to update to beta 7.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on September 25, 2020, 03:31:54 pm
Jonas,

I just restored Apple DTK to Beta 8 and I can't compile FPC again according wiki (https://wiki.freepascal.org/macOS_Big_Sur_changes_for_developers#ARM64.2FAArch64.2FAppleSilicon_Support).

Quote
*** Compiler ppcx64 not found.  Stop

Code: Pascal  [Select][+][-]
  1. mac@Igors-Mac freepascal % make distclean
  2. make: -iVSPTPSOTO: Command not found
  3. /bin/rm -f build-stamp.*
  4. /bin/rm -f base.build-stamp.*
  5. mac@Igors-Mac freepascal % make FPC=ppcx64 OPT="-ap -FD/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin -XR/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" CPU_TARGET=aarch64 -j 4 FPMAKEOPT="-T 4" all > build.log
  6. Makefile:135: *** Compiler ppcx64 not found.  Stop.

I downloaded FPC:
Code: Pascal  [Select][+][-]
  1. git clone https://github.com/graemeg/freepascal

Xcode 12.2 Beta is installed.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on September 25, 2020, 06:36:01 pm
You have to reinstall FPC 3.2.0 after restoring your DTK.
TinyPortal © 2005-2018