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.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on September 27, 2020, 05:05:04 pm
Jonas,
Thanks! So stupid mistake after many recompilations :)
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on October 02, 2020, 01:53:07 pm
Jonas,

I have a problem with compiling native FPC for ARM64.

It fails on this stage:

Code: Pascal  [Select][+][-]
  1. mac@Igors-Mac freepascal % make FPC=$PWD/ppca64 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" -j 4 FPMAKEOPT="-T 4" OVERRIDEVERSIONCHECK=1 all > build.log
  2. make: *** clean: No such file or directory.  Stop.
  3. make[5]: *** [rtlclean] Error 2
  4. make[4]: *** [next] Error 2
  5. make[3]: *** [ppc1.exe] Error 2
  6. make[2]: *** [cycle] Error 2
  7. make[1]: *** [compiler_cycle] Error 2
  8. make: *** [build-stamp.-] Error 2

I just downloaded the latest source code of FPC:

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

Xcode 12.2 Beta is installed in Applications.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on October 02, 2020, 02:20:28 pm
What does build.log contain?
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on October 02, 2020, 02:28:31 pm
Code: Pascal  [Select][+][-]
  1. /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make compiler_cycle RELEASE=1
  2. You have overriden the starting compiler versioncheck while using starting compiler version . This situation is not supported and strange things and errors may happen. Remove OVERRIDEVERSIONCHECK=1 to fix this.
  3. /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make -C compiler cycle
  4. /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make tempclean
  5. /bin/rm -f ppcross ppc ppc1.exe ppc2.exe ppc3.exe ./msg2inc.exe pp1.wpo pp2.wpo
  6. /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make ppc3.exe
  7. /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make 'OLDFPC=' next CYCLELEVEL=1
  8. /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make rtlclean
  9. /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make -C  clean
  10.  
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on October 02, 2020, 02:48:03 pm
If you go in the compiler directory and execute the following, what does it print?
Code: [Select]
make FPC=$PWD/../ppca64 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" -j 4 FPMAKEOPT="-T 4" OVERRIDEVERSIONCHECK=1 RELEASE=1 info

Also, what does "make --version" print?
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on October 02, 2020, 03:19:40 pm
In /freepascal/compiler folder:

Code: Pascal  [Select][+][-]
  1. mac@Igors-Mac compiler % make FPC=$PWD/../ppca64 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" -j 4 FPMAKEOPT="-T 4" OVERRIDEVERSIONCHECK=1 RELEASE=1 info
  2.  
  3. == Package info ==
  4. Package Name..... compiler
  5. Package Version.. 3.3.1
  6.  
  7. == Configuration info ==
  8.  
  9. FPC.......... /Users/mac/WnSoft/Development/freepascal/compiler/../ppca64
  10. FPC Version.. 3.3.1
  11. Source CPU... aarch64
  12. Target CPU... aarch64
  13. Source OS.... darwin
  14. Target OS.... darwin
  15. Full Source.. aarch64-darwin
  16. Full Target.. aarch64-darwin
  17. SourceSuffix. aarch64-darwin
  18. TargetSuffix. aarch64-darwin
  19. FPC fpmake... /Users/mac/WnSoft/Development/freepascal/compiler/../ppca64
  20.  
  21. == Directory info ==
  22.  
  23. Required pkgs... rtl rtl
  24.  
  25. Basedir......... /Users/mac/WnSoft/Development/freepascal/compiler
  26. FPCDir.......... ..
  27. CrossBinDir.....
  28. UnitsDir........
  29. PackagesDir..... .. ../packages
  30.  
  31. GCC library.....
  32. Other library...
  33.  
  34. == Tools info ==
  35.  
  36. As........ as
  37. Ld........ ld
  38. Ar........ ar
  39. Rc........ rc
  40.  
  41. Mv........ /bin/mv
  42. Cp........ /bin/cp
  43. Rm........ /bin/rm
  44. GInstall.. /usr/bin/install
  45. Echo...... /bin/echo
  46. Shell..... /bin/sh
  47. Date...... /bin/date
  48. FPCMake... /usr/local/bin/fpcmake
  49. PPUMove... /usr/local/bin/ppumove
  50. Zip....... /usr/bin/zip
  51.  
  52. == Object info ==
  53.  
  54. Target Loaders........
  55. Target Units..........
  56. Target Implicit Units.
  57. Target Programs....... pp
  58. Target Dirs........... utils
  59. Target Examples.......
  60. Target ExampleDirs....
  61.  
  62. Clean Units.........
  63. Clean Files.........
  64.  
  65. Install Units.......
  66. Install Files.......
  67.  
  68. == Install info ==
  69.  
  70. DateStr.............. 20201002
  71. ZipName.............. compiler
  72. ZipPrefix............
  73. ZipCrossPrefix.......
  74. ZipSuffix............ .aarch64-darwin
  75. FullZipName.......... compiler.aarch64-darwin
  76. Install FPC Package.. y
  77.  
  78. Install base dir..... /usr/local/lib/fpc/3.3.1
  79. Install binary dir... /usr/local/bin
  80. Install library dir.. /usr/local/lib
  81. Install units dir.... /usr/local/lib/fpc/3.3.1/units/aarch64-darwin/compiler
  82. Install source dir... /usr/local/share/src/fpc-3.3.1/compiler
  83. Install doc dir...... /usr/local/share/doc/fpc-3.3.1/compiler
  84. Install example dir.. /usr/local/share/examples/fpc-3.3.1/compiler
  85. Install data dir..... /usr/local/lib/fpc/3.3.1
  86.  
  87. Dist destination dir. /Users/mac/WnSoft/Development/freepascal/compiler
  88. Dist zip name........

Code: Pascal  [Select][+][-]
  1. mac@Igors-Mac compiler % make --version
  2. GNU Make 3.81
  3. Copyright (C) 2006  Free Software Foundation, Inc.
  4. This is free software; see the source for copying conditions.
  5. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
  6. PARTICULAR PURPOSE.
  7.  
  8. This program built for i386-apple-darwin11.3.0

P.S. I have Beta 9 on this DTK. I restored DTK in DFU mode to Beta 8, installed Xcode 12.2 Beta and then updated to Beta 9.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on October 02, 2020, 08:29:09 pm
It turns out to be yet another bug in the codesigning verification functionality. It works if you copy instead of move compiler/ppca64 to the current directory (i.e., use "cp compiler/ppca64 ." as step 2)
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on October 05, 2020, 02:32:18 pm
Jonas,

Thanks, I used cp command on Step 2:

Code: Pascal  [Select][+][-]
  1. cp compiler/ppca64 .

But the same error on Step 3:

Code: Pascal  [Select][+][-]
  1. mac@Igors-Mac freepascal % make FPC=$PWD/ppca64 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" -j 4 FPMAKEOPT="-T 4" OVERRIDEVERSIONCHECK=1 all > build.log
  2. make: *** clean: No such file or directory.  Stop.
  3. make[5]: *** [rtlclean] Error 2
  4. make[4]: *** [next] Error 2
  5. make[3]: *** [ppc1.exe] Error 2
  6. make[2]: *** [cycle] Error 2
  7. make[1]: *** [compiler_cycle] Error 2
  8. make: *** [build-stamp.-] Error 2

Code: Pascal  [Select][+][-]
  1. /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make compiler_cycle RELEASE=1
  2. You have overriden the starting compiler versioncheck while using starting compiler version . This situation is not supported and strange things and errors may happen. Remove OVERRIDEVERSIONCHECK=1 to fix this.
  3. /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make -C compiler cycle
  4. /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make tempclean
  5. /bin/rm -f ppcross ppc ppc1.exe ppc2.exe ppc3.exe ./msg2inc.exe pp1.wpo pp2.wpo
  6. /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make ppc3.exe
  7. /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make 'OLDFPC=' next CYCLELEVEL=1
  8. /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make rtlclean
  9. /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make -C  clean
  10.  
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on October 05, 2020, 02:41:24 pm
It worked for me... Maybe try deleting the old ppca64 in the top-level fpc directory before copying the new one. You can check whether it worked without executing the "make" command by just executing that ppca64 binary (./ppca64). If you immediately get a "killed" message, it indicates codesigning shenanigans. There's also a thread about this issue on the Apple developer forums.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on October 05, 2020, 03:54:09 pm
Jonas,

I deleted fps and lazarus and downloaded them again.

Now fps compiles fine for arm64.

Thanks for your help.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on October 06, 2020, 03:36:11 pm
Jonas,

Every time I start Lazarus I see an error message that Fppcfg is missing (fppcfg.cfg).
Can you advice how to fix it?
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on October 06, 2020, 03:37:57 pm
No, I only work on the compiler. I have no clue what that file is for or how it is supposed to be created. It's not part of fpc itself.
Title: Re: Apple Developer Transition Kit
Post by: trev on October 07, 2020, 11:47:16 am
Every time I start Lazarus I see an error message that Fppcfg is missing (fppcfg.cfg).

Do you mean /etc/fppkg.cfg ?
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on October 07, 2020, 01:26:22 pm
Do you mean /etc/fppkg.cfg ?

Yes, and I can't create a new fppkg.cfg file. No rights.

It seems to be some new problem with Apple DTK on Beta 9.

Earlier I didn't had this problem with macOS Big Sure Beta 1-5. Recently I restored DTK to Beta 9 and have this problem with Lazarus. As you can see from my previous posts, I downloaded Trunk version of FPC and Lazarus and compiled it according instructions from Jonas.
Title: Re: Apple Developer Transition Kit
Post by: trev on October 07, 2020, 01:50:41 pm
The "user" as opposed to "global" version is in /Users/<name>/.config/fppkg.cfg ... surely you can create that one?
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on October 07, 2020, 02:52:06 pm
By default, it shows path: /etc/fppkg.cfg

When I tried to change path in a combobox to /Users/mac/.config/fppkg.cfg

I immediately got Access violation error in Lazarus and it aborts.

I tried to recreate this configuration - the same Access violation error.

I checked this file - /Users/mac/.config/fppkg.cfg
It exists and seems to be OK on first glance.

Note, that I have a clear new macOS installation, with no old versions of Lazarus or FPC.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on October 07, 2020, 05:18:42 pm
Do you mean /etc/fppkg.cfg ?

Yes, and I can't create a new fppkg.cfg file. No rights.
That file gets created by the official FPC 3.2.0 installer. I just checked by removing it and reinstalling FPC 3.2.0 as downloaded from https://www.freepascal.org under Beta 9, and it got recreated.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on October 08, 2020, 03:53:06 pm
Jonas,

I tried to reinstall official FPC 3.2.0 installer.

It solved the problem with fppkg.cfg file when I run Lazarus. But now default compiler is for x86-64.

I compiled and installed native AARCH64 compiler according Lazarus wiki, steps 1-5.

Now I have again AARCH64 compiler. But fppkg.cfg error appears again when I run Lazarus.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on October 29, 2020, 08:41:26 am
Jonas,

Is it possible to compile native ARM64 code for Apple Silicon on Intel Mac (with Big Sur and Xcode 12)?

Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on October 30, 2020, 09:48:45 pm
Is it possible to compile native ARM64 code for Apple Silicon on Intel Mac (with Big Sur and Xcode 12)?
Yes. Execute step 1 of the instructions on an Intel Mac, and you'll have the cross-compiler. Skip steps 2 and 3. Execute step 4, but modified for a cross-installation:
Code: [Select]
sudo make FPC=$PWD/compiler/ppcrossa64 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" CROSSINSTALL=1 install
Similar for step 5:
Code: [Select]
sudo mv /usr/local/lib/fpc/3.3.1/ppcrossa64 /usr/local/lib/fpc/3.3.1/ppca64
sudo ln -sf /usr/local/lib/fpc/3.3.1/ppca64 /usr/local/bin

And in step 6, only perform the configuration modifications when targeting AArch64:
Code: [Select]
#include /etc/fpc.cfg
#ifdef cpuaarch64
-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
#endif
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on October 31, 2020, 09:18:08 pm
Jonas,

Thanks! I'll try on Monday.

Can I switch a target in lazbuild for x86-64 and AARCH64 to compile two versions?

then I plan to use lipo to create Universal Binary.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on October 31, 2020, 09:19:22 pm
Probably. I only use Lazarus as a code editor myself, so I can't help with that.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 01, 2020, 03:05:07 pm
Jonas,

I meant can I switch a target in the Project Options between AARCH64 and x86-64? To build a required version.

Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on November 01, 2020, 03:27:20 pm
I would expect so. Keep in mind that you'll be using FPC 3.2.0 for Intel and FPC 3.3.1 for AArch64, so watch out that you don't accidentally start relying on 3.3.1-only features or fixes.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 01, 2020, 05:41:38 pm
Jonas,

Thanks, I've understood now.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 02, 2020, 06:58:16 pm
Now I have almost fully ready version for ARM in addition to Intel version. The app works very well. Thanks to FPC team for their great work. Special thanks to Jonas for his advices and instructions. I plan to build a final DMG installation soon.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 12, 2020, 02:27:58 pm
System.GetCPUCount() always returns "1" on Apple Silicon CPU. It should be 4 or maybe 8 cores.
Title: Re: Apple Developer Transition Kit
Post by: Fred vS on November 12, 2020, 02:32:59 pm
System.GetCPUCount() always returns "1" on Apple Silicon CPU. It should be 4 or maybe 8 cores.

The same here on Linux and Intel i5, always only "1" cpu.
Title: Re: Apple Developer Transition Kit
Post by: Fred vS on November 12, 2020, 02:46:34 pm
System.GetCPUCount() always returns "1" on Apple Silicon CPU. It should be 4 or maybe 8 cores.

The same here on Linux and Intel i5, always only "1" cpu.

But maybe  GetCPUCount() return the number of CPU and not the number of cores inside the CPU.

If so, ok and sorry for the noise.
Title: Re: Apple Developer Transition Kit
Post by: marcov on November 12, 2020, 02:58:42 pm
On 64-bit Windows it returns "8", which is my 4 physical core + 4 hyperthreading cores.
Title: Re: Apple Developer Transition Kit
Post by: Fred vS on November 12, 2020, 03:12:06 pm
On 64-bit Windows it returns "8", which is my 4 physical core + 4 hyperthreading cores.

Huh, indeed, on Linux compiling GetCPUCount() with wine fpc.exe and then run the Windows binary with
wine gives "4" as result!

But same code compiled for Linux and run the Linux binary gives "1" as result.

[EDIT]
And with the Linux command:
Code: Bash  [Select][+][-]
  1. $ lscpu

It gives "8" cpu.
Title: Re: Apple Developer Transition Kit
Post by: skalogryz on November 12, 2020, 05:35:58 pm
System.GetCPUCount() always returns "1" on Apple Silicon CPU. It should be 4 or maybe 8 cores.
the function doesn't seem to be implemented for Unix systems.

What does processorCount (https://developer.apple.com/documentation/foundation/nsprocessinfo/1415622-processorcount) return?
Title: Re: Apple Developer Transition Kit
Post by: skalogryz on November 12, 2020, 06:11:02 pm
But same code compiled for Linux and run the Linux binary gives "1" as result.
how about this code:
Code: Pascal  [Select][+][-]
  1. uses
  2.   cthreads;
  3.  
  4. function get_nprocs_conf: integer; cdecl; external;
  5.  
  6. function GetCPUCountLinux: Integer;
  7. begin
  8.   Result := get_nprocs_conf;
  9. end;
  10.  
  11. begin
  12.   writeln('proc count: ', GetCPUCountLinux);
  13. end.  
  14.  
Title: Re: Apple Developer Transition Kit
Post by: skalogryz on November 12, 2020, 06:41:52 pm
another Linux/macOS version:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H+}
  2.  
  3. uses
  4.   ctypes;
  5.  
  6. const
  7.   // the value changes across Unix OS-es
  8.   _SC_NPROCESSORS_ONLN           = {$ifdef darwin}58{$endif} // macOS
  9.                                    {$else}84{$endif};  // linux
  10.  
  11. function sysconf(conf: cint): clong; cdecl; external;
  12.  
  13. function GetCPUCountUnix: Integer;
  14. begin
  15.   Result := sysconf(_SC_NPROCESSORS_ONLN);
  16. end;
  17.  
  18. begin
  19.   writeln('proc count: ', GetCPUCountUnix);
  20. end.      
  21.  
Title: Re: Apple Developer Transition Kit
Post by: Fred vS on November 12, 2020, 09:49:05 pm
But same code compiled for Linux and run the Linux binary gives "1" as result.
how about this code:
Code: Pascal  [Select][+][-]
  1. uses
  2.   cthreads;
  3.  
  4. function get_nprocs_conf: integer; cdecl; external;
  5.  
  6. function GetCPUCountLinux: Integer;
  7. begin
  8.   Result := get_nprocs_conf;
  9. end;
  10.  
  11. begin
  12.   writeln('proc count: ', GetCPUCountLinux);
  13. end.  
  14.  

Yep, it works:

Code: Bash  [Select][+][-]
  1. ~> ./testcpu
  2. proc count: 8
Title: Re: Apple Developer Transition Kit
Post by: Fred vS on November 12, 2020, 09:58:41 pm
another Linux/macOS version:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H+}
  2.  
  3. uses
  4.   ctypes;
  5.  
  6. const
  7.   // the value changes across Unix OS-es
  8.   _SC_NPROCESSORS_ONLN           = {$ifdef darwin}58{$endif} // macOS
  9.                                    {$else}84{$endif};  // linux
  10.  
  11. function sysconf(conf: cint): clong; cdecl; external;
  12.  
  13. function GetCPUCountUnix: Integer;
  14. begin
  15.   Result := sysconf(_SC_NPROCESSORS_ONLN);
  16. end;
  17.  
  18. begin
  19.   writeln('proc count: ', GetCPUCountUnix);
  20. end.      
  21.  

This one gives at compilation:

Quote
Compiling testcpu.pas
Linking testcpu
/usr/bin/ld: testcpu.o: in function `P$TESTCPU_$$_GETCPUCOUNTUNIX$$LONGINT':
testcpu.pas:(.text.n_p$testcpu_$$_getcpucountunix$$longint+0x11): undefined reference to `sysconf'
testcpu.pas(22,5) Error: Error while linking
testcpu.pas(22,5) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted


Title: Re: Apple Developer Transition Kit
Post by: skalogryz on November 12, 2020, 10:40:40 pm
please add cthreads to the uses clause. This should link the required library
Title: Re: Apple Developer Transition Kit
Post by: Fred vS on November 12, 2020, 10:44:13 pm
please add cthreads to the uses clause. This should link the required library

Ha, ok, now it compiles ok and the result is ok too.
Code: Pascal  [Select][+][-]
  1. ~> ./testcpu
  2. proc count: 8
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 13, 2020, 03:32:46 pm
skalogryz,

Thanks for your reply!

Your code works fine on both Macs - Intel and Apple DTK:

DTK returns "8" cores.

Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H+}
  2.  
  3. uses
  4.   ctypes, cthreads;
  5.  
  6. const
  7.   // the value changes across Unix OS-es
  8.   _SC_NPROCESSORS_ONLN           = {$ifdef darwin}58{$endif} // macOS
  9.                                    {$else}84{$endif};  // linux
  10.  
  11. function sysconf(conf: cint): clong; cdecl; external;
  12.  
  13. function GetCPUCountUnix: Integer;
  14. begin
  15.   Result := sysconf(_SC_NPROCESSORS_ONLN);
  16. end;
  17.  
  18. begin
  19.   writeln('proc count: ', GetCPUCountUnix);
  20. end.

Another variant doesn't link on Apple DTK for aarch64:

Code: Pascal  [Select][+][-]
  1. uses
  2.   cthreads;
  3.  
  4. function get_nprocs_conf: integer; cdecl; external;
  5.  
  6. function GetCPUCountLinux: Integer;
  7. begin
  8.   Result := get_nprocs_conf;
  9. end;
  10.  
  11. begin
  12.   writeln('proc count: ', GetCPUCountLinux);
  13. end.  
Title: Re: Apple Developer Transition Kit
Post by: marcov on November 13, 2020, 03:42:46 pm
What value does the number of logical cores _alone_ have? It is only useful if you also have the physical cores. (e.g. if you have 6 real cores + HT, then start 8 threads. But starting twelve is nearly always overkill)
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 13, 2020, 03:49:36 pm
Apple DTK has 8 cores (4 high-speed and 4 energy saving).
Title: Re: Apple Developer Transition Kit
Post by: skalogryz on November 13, 2020, 04:02:54 pm
Another variant doesn't link on Apple DTK for aarch64:
it should not link on macOS. get_nprocs_conf() is a Linux specific function.

What about processorCount (https://developer.apple.com/documentation/foundation/nsprocessinfo/1415622-processorcount)?

The code might look like thise
Code: Pascal  [Select][+][-]
  1. uses
  2.   CocoaAll;
  3. {$modeswitch objectiveC2}
  4.  
  5. begin
  6.   writeln('proc count: ', NSProcessInfo processInfo.processorCount);
  7. end.  
Title: Re: Apple Developer Transition Kit
Post by: marcov on November 13, 2020, 06:40:34 pm
Apple DTK has 8 cores (4 high-speed and 4 energy saving).

Can they all work in parallel? If not, than that is the a different setup, but the same problem.

IOW what good does the figure "8" for cores if only 4 can work at any one given time?
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on November 13, 2020, 08:48:51 pm
Apple DTK has 8 cores (4 high-speed and 4 energy saving).

Can they all work in parallel?
Yes.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 14, 2020, 02:14:25 pm
skalogryz,

Thanks, I'll try NSProcessInfo processInfo.processorCount
It would be a simpliest code for macOS.

Jonas,

Did you see any articles or confirmations about using of 8-cores in Apple DTK or M1?

Quote
"The Geekbench 5 result reports the DTK as having only four cores while it is known that the A12Z has, in fact, eight CPU cores. It is very well possible that Rosetta 2 is seeing only the four high performance cores and not the efficiency ones."
https://www.notebookcheck.net/First-A12Z-Bionic-DTK-Geekbench-5-benchmarks-show-Apple-s-transition-holds-immense-promise-only-a-28-in-drop-seen-in-single-core-score-compared-to-the-MacBook-Air-2020.477595.0.html
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on November 14, 2020, 03:13:52 pm
You don't need external confirmation since you have a DTK yourself. Just create a program that starts 7 threads that execute "while true do ;" (and do the same in the main program) and look at the cpu usage reported by top (or Activity Viewer). Then try the same with 3 threads and 11 threads. You'll get ~390%/~790%/~790% reported cpu usage for respectively 4/8/12 loops executing concurrently.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 16, 2020, 09:24:23 am
Jonas,

You're right. It's easy to check.

The only question - performance of last 4 cores. Probably the total performance of these high-efficienty cores would be as 2 high-performance cores.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 16, 2020, 12:50:56 pm

What about processorCount (https://developer.apple.com/documentation/foundation/nsprocessinfo/1415622-processorcount)?

The code might look like thise
Code: Pascal  [Select][+][-]
  1. uses
  2.   CocoaAll;
  3. {$modeswitch objectiveC2}
  4.  
  5. begin
  6.   writeln('proc count: ', NSProcessInfo processInfo.processorCount);
  7. end.  

skalogryz,

I can't compile this code on any Mac.
Title: Re: Apple Developer Transition Kit
Post by: skalogryz on November 16, 2020, 01:40:39 pm
Code: Pascal  [Select][+][-]
  1. uses
  2.   CocoaAll;
  3. {$modeswitch objectiveC2}
  4.  
  5. begin
  6.   writeln('proc count: ', NSProcessInfo.processInfo.processorCount);
  7. end.
Title: Re: Apple Developer Transition Kit
Post by: JdeHaan on November 16, 2020, 02:01:42 pm
The mode switch should be above the uses clause.
Code: Pascal  [Select][+][-]
  1. program processorcount;
  2. {$modeswitch objectiveC2}
  3.  
  4. uses
  5.   CocoaAll;
  6.  
  7. begin
  8.   writeln('proc count: ', NSProcessInfo.processInfo.processorCount);
  9. end.
  10.  
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 16, 2020, 04:44:04 pm
Thanks, it works now.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on November 16, 2020, 07:54:10 pm
Jonas,

You're right. It's easy to check.

The only question - performance of last 4 cores. Probably the total performance of these high-efficienty cores would be as 2 high-performance cores.
Not necessarily. Performance wins usually decrease exponentially as cores become more powerful/complex, so it could easily be more than that. It also illustrates the limited use of a singular "processorcount" value. Other cases where it means little is in case of NUMA configurations and hyperthreading.
Title: Re: Apple Developer Transition Kit
Post by: trev on November 16, 2020, 10:58:50 pm
HW selectors for sysctlbyname which are useful in this context:

* hw.ncpu   - The maximum number of processors that could be available this boot
* hw.activecpu   - The number of processors currently available for executing threads
* hw.physicalcpu - The number of physical processors available in the current power management mode
* hw.logicalcpu  - The number of logical processors available in the current power management mode

See the Wiki article Accessing macOS System Information (https://wiki.lazarus.freepascal.org/Accessing_macOS_System_Information).
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 17, 2020, 09:10:10 pm
Thanks! Great info. I'll learn it more.
Title: Re: Apple Developer Transition Kit
Post by: marcov on November 17, 2020, 10:43:34 pm
Not necessarily. Performance wins usually decrease exponentially as cores become more powerful/complex, so it could easily be more than that. It also illustrates the limited use of a singular "processorcount" value. Other cases where it means little is in case of NUMA configurations and hyperthreading.

There are also some reports that the extreme bandwidth of the fast cores leads to memory bandwidth saturation, where the slower core could eat memory bandwidth of the faster cores.

https://www.anandtech.com/show/16252/mac-mini-apple-m1-tested
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 19, 2020, 02:02:18 pm
Currently FPC trunk can compile to "arm64" target for macOS.

In the final release of Big Sur Apple compiles own apps in "arm64e". You can check it using
lipo -archs /Applications/Safari.app/Contents/MacOS/Safari

It seems that arm64e is a new generation of arm64:

- Pointer authentication
- Nested virtualization
- Advanced SIMD complex number support
- Improved Javascript data type conversion support
- A change to the memory consistency model
- ID mechanism support for larger system-visible caches

Is it possible that "arm64" will be declared as deprecated in nearest future?

Can FPC compile to arm64e ?

https://stackoverflow.com/questions/52624308/xcode-arm64-vs-arm64e
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on November 19, 2020, 02:40:47 pm
Quote
In the final release of Big Sur Apple compiles own apps in "arm64e".
Apple has been doing that since several betas already (maybe even from the first beta, but I didn't have a DTK yet at that point).

Quote
It seems that arm64e is a new generation of arm64:
No, it's just an extension.

Quote
Is it possible that "arm64" will be declared as deprecated in nearest future?
Definitely not in the nearest future, since building your own applications for arm64e is not even supported yet by Apple itself: https://developer.apple.com/forums/thread/652340

Most likely not afterwards either.

Quote
Can FPC compile to arm64e ?
Currently only by using the LLVM backend.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 19, 2020, 04:13:47 pm
Jonas,

Thank you very much for the detailed reply!
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 19, 2020, 06:54:45 pm
Jonas,

I plan to compile a final version of our app as Universal Binary (Intel + AARCH64).

You explained (https://forum.lazarus.freepascal.org/index.php/topic,50476.msg382427.html#msg382427) me how to configure cross compilation on Intel Mac.

What is better:
A. Use a stable Lazarus 2.0.10 with FPC Trunk 3.3.1?
B. Or Lazarus Trunk + FPC Trunk 3.3.1?

I guess that official release of Lazarus with FPC will not be released soon.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on November 19, 2020, 08:07:20 pm
What is better:
A. Use a stable Lazarus 2.0.10 with FPC Trunk 3.3.1?
B. Or Lazarus Trunk + FPC Trunk 3.3.1?
You can also use FPC fixes_3_2 (I have merged the macOS/AArch64 support there, except for the inline assembly vector instructions support for now). And you can also use the lazarus fixes_2_0 branch.

For FPC, I would recommend the fixes_3_2 branch. There are several known bugs in peephole optimizations that have been added for AArch64 in trunk, and those do not exist in fixes_3_2. For Lazarus, I can't recommend anything. There is no general "best" combination. It all depends on whether you need any fixes/features that are only available on a particular Lazarus branch. I don't know whether there are any AArch64/macOS 11.0-specific fixes in Lazarus (and/or other fixes that your application depends on), and if so on which branches they are.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 19, 2020, 08:39:00 pm
Jonas,

Thanks for the great advices!

I'll try tomorrow to compile/install fpc fixes_3_2 branch on Intel Mac.

And Lazarus 2.0 fixes.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 20, 2020, 09:38:06 am
Jonas,

Can you update wiki "ARM64/AArch64/AppleSilicon Support"?

Xcode now is a stable version "Xcode.app", probably we can remove "Xcode-beta.app" from examples?

And it would be great to add instrusctions for cross-compilation for aarch64 on Intel Mac which you gave me recently.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on November 20, 2020, 10:01:13 am
It's a wiki, you can edit it too! :)
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 20, 2020, 10:43:49 am
Jonas,

I could compile cross-platform compiler fpc 3.2.0 fixes on Intel Mac. And with existing Lazarus 2.0.10 I can target binary for x86-64 or arm64.

But if I now try to compile Lazarus from sources - 2.0.10 or 2.0 branch fixes I get the following error:

make bigide

Code: Pascal  [Select][+][-]
  1. Compiling carbonbars.pp
  2. carbonbars.pp(16,2) Error: User defined: only cpu i386 is supported
  3. Compiling carbonprivate.pp
  4. Compiling carbondef.pp
  5. carbondef.pp(187,1) Fatal: There were 1 errors compiling module, stopping
  6. Fatal: Compilation aborted
  7. make[3]: *** [../lcl.ppu] Error 1
  8. make[2]: *** [carbon_all] Error 2
  9. make[1]: *** [interfaces] Error 2
  10. make: *** [lcl] Error 2
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on November 20, 2020, 11:22:20 am
See https://wiki.freepascal.org/Installing_Lazarus_on_macOS#Lazarus_Fixes_2.0
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 20, 2020, 03:54:39 pm
Jonas,

Thanks! I successfully compiled Lazarus 2.0-fixes now.

I have a strange problem on second Intel Mac with FPC fixes tree (3.2.1).

It was compiled and installed without errors. But I can't use it for aarch64 target. Once I choose aarch64 in Project Options and click OK button, I see an error - /usr/local/bin/fpc doesn't support aarch64 target.
In Preferences of Lazarus I see: /usr/local/bin/fpc
Also /usr/local/bin/fpc has an old file date (May 2020) and shows 3.2.0 version

I have a new file: /usr/local/lib/fpc/3.2.1/ppca64

On first Mac everything works correctly.

I tried to recompile FPC 3.2.1 (fixes tree) with the same result.

I used your instructions:
https://forum.lazarus.freepascal.org/index.php/topic,50476.msg382427.html#msg382427
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on November 21, 2020, 05:29:12 pm
See step 5 on https://wiki.freepascal.org/macOS_Big_Sur_changes_for_developers#ARM64.2FAArch64.2FAppleSilicon_Support (replace the version number)
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 21, 2020, 05:38:43 pm
Jonas,

Yes, I replaced version number to 3.2.1 (fpc 3.2.0 with fixes).

sudo ln -sf /usr/local/lib/fpc/3.2.1/ppca64 /usr/local/bin

I tried 5 times to recompile FPC and re-download sources again.

When I type "fpc" in Terminal, I see version "3.2.0". Does it correct?

Probably /usr/bin/local/fpc incorrectly calls required version?

On Apple DTK when I type "fpc" I see version "3.2.1".

Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on November 21, 2020, 05:41:09 pm
Jonas,

Yes, I replaced version number to 3.2.1 (fpc 3.2.0 with fixes).

sudo ln -sf /usr/local/lib/fpc/3.2.1/ppca64 /usr/local/bin

I tried 5 times to recompile FPC and re-download sources again.

When I type "fpc" in Terminal, I see version "3.2.0". Does it correct?
Yes, because the default compiler binary that gets started by "fpc" is the one for the host platform (technically, for the platform for which the "fpc" binary itself was compiled). On an Intel Mac that will be ppcx64, which is version 3.2.0 on your machine. If you use "fpc -Paarch64", you should see 3.2.1 instead (since that will start the AArch64 version of the compiler).
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 21, 2020, 06:28:35 pm
Yes, on Macbook with Intel I see version "3.2.1" when I type "fpc -Paarch64".
And I can compile project with a target aarch64.

I will check iMac on Monday.
Title: Re: Apple Developer Transition Kit
Post by: skalogryz on November 23, 2020, 08:11:40 am
But if I now try to compile Lazarus from sources - 2.0.10 or 2.0 branch fixes I get the following error:

make bigide

carbonbars.pp(16,2) Error: User defined: only cpu i386 is supported

Code: Pascal  [Select][+][-]
  1. make bigide LCL_PLATFORM=cocoa
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 23, 2020, 01:09:02 pm
Jonas,

I've got this result in Terminal:

Code: Pascal  [Select][+][-]
  1. bash-3.2$ fpc -Paarch64
  2. Free Pascal Compiler version 3.2.1 [2020/11/20] for aarch64

But when I choose target aarch64 in Project Options in Lazarus 2.0.10 (release). I get this error on Intel Mac:

Quote
Compiler "/usr/local/bin/fpc" does not support target aarch64-macos

The same error in Lazarus 2.0.11 fixes.
Title: Re: Apple Developer Transition Kit
Post by: Jonas Maebe on November 23, 2020, 06:51:11 pm
The correct target is Darwin, not MacOS (which will be renamed to "Classic MacOS" in FPC 3.2.2 to reduce confusion).
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 23, 2020, 08:34:57 pm
Jonas,

Thanks, I've understood. I'll try tomorrow with target "Darwin" + aarch64 on iMac.

It's a bit strange that first Macbook can compile to aarch64 with target OS "By default" (which works as "darwin").

But another iMac wrongly interprets "By default" as "classic macOS" and cannot compile to darwin-aarch64.

Both Macs with Big Sur 11.0.1, Xcode 12.2, Lazarus 2.0.10 and FPC 3.2.1 (fixes).

Probably some wrong old settings in /etc/fpc.cfg ?
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 24, 2020, 01:07:14 pm
Jonas,

I tried again on iMac with Big Sur, but even with target darwin + aarch64 I get this error:

Code: Pascal  [Select][+][-]
  1. Compiler "/usr/local/bin/fpc" does not support target aarch64-darwin

Code: Pascal  [Select][+][-]
  1. bash-3.2$ fpc -Paarch64
  2. Free Pascal Compiler version 3.2.1 [2020/11/20] for aarch64

Can I manually somehow overwrite fpc binaries to get it work?
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on November 26, 2020, 11:05:01 am
Embarcadero promisses (https://blogs.embarcadero.com/rad-studio-roadmap-november-2020/) ARM64 support for Delphi only at second half of 2021. Whereas FPC 3.2.0 fixes already can compile for ARM64 target in macOS.
Bravo to developers of FPC!
Title: Re: Apple Developer Transition Kit
Post by: trev on November 26, 2020, 10:47:18 pm
Embarcadero promisses (https://blogs.embarcadero.com/rad-studio-roadmap-november-2020/) ARM64 support for Delphi only at second half of 2021.

Given their previous over-promising and under-delivering for 64 bit macOS and iOS compilers, I wouldn't be holding my breath.

Quote
Whereas FPC 3.2.0 fixes already can compile for ARM64 target in macOS.
Bravo to developers of FPC!

Indeed. Another reason to use FPC + Lazarus rather than EMB's product.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on December 04, 2020, 07:13:40 pm
I created first Universal App, signed, notarized DMG. It works fine on my Apple DTK and on Intel Mac.

But on real Mac Mini with M1 we've got an error for native aarch64 version:

Quote
Dec  4 11:35:57 MacMini com.apple.xpc.launchd[1]: Coalition Cache Hit: app<application.TestApp.27827332.27827354(501)> [1370]
Dec  4 11:35:57 MacMini com.apple.xpc.launchd[1] (application.TestApp.27827332.27827354[1787]): Service exited with abnormal code: 217

So I guess that we have to buy real Mac with M1 for testing. DTK can mask problems.
Title: Re: Apple Developer Transition Kit
Post by: skalogryz on December 04, 2020, 07:33:47 pm
Quote
Service exited with abnormal code: 217

It seems to be FPC run-time error:
Quote
217 Unhandled exception occurred
An exception occurred, and there was no exception handler present. The sysutils unit installs a default exception handler which catches all exceptions and exits gracefully.
Title: Re: Apple Developer Transition Kit
Post by: ChrisR on December 04, 2020, 07:52:27 pm
Igor,
 I have both a DTK and M1. I have not seen any bugs on the M1 that were not present on the DTK. However, there are several documented FPC bugs for situations where the optimization level is greater than -O1. My current approach is to develop everything with the FPC compiler (which is very quick to compile and nicely integrated into Lazarus) and then to compile the release builds with LLVM.

Optionally, for extra performance, I also add a couple of custom compiler options for LLVM that Jonas suggested. I do this by adding a couple lines to the .lpi file (I can not work out how to make a conditional for LLVM detection in the compiler options):

<CustomOptions Value="-dDisableLCLGIF
-Clflto
-Clfltonosystem"/>


So my build/notarization script cross-compiles and uses lipo to make a universal binary:

lazbuild -B --compiler=~/src/fpcllvm/lib/fpc/3.3.1/ppcx64 --ws=cocoa  --cpu=x86_64 ~/src/MRIcroGL12/MRIcroGL_Metal_llvm.lpi

lazbuild -B --compiler=~/src/fpcllvm/lib/fpc/3.3.1/ppca64 --ws=cocoa  --cpu=aarch64 ~/src/MRIcroGL12/MRIcroGL_Metal_llvm.lpi

Compared to the non-optimized FPC AArch64, this leads to substantially faster performance. Here are the times in milliseconds for a few tasks:

M1-FPC   
init   329
minmax   319
rgba   189
M1-LLVM   
init   126
minmax   81
rgba   104

I do expect FPC will close this gap as the AArch64 optimization matures - I urge everyone to help sponsor Kit's work on this
  https://www.patreon.com/curiouskit/posts

Since LLVM/Clang is what Apple uses for all their tools, it seems very optimized. All my Lazarus projects just work, including those that use OpenGL and Metal. I suspect this will resolve the bugs you are encountering, and should allow you to build perfectly fine M1 code on your DTK.
Title: Re: Apple Developer Transition Kit
Post by: Igor Kokarev on December 04, 2020, 08:21:45 pm
skalogryz,
Chris,

Many thanks for your quick responses and advices!

I compiled my app with FPC 3.2.1 fixes on two different Macs. With optimizations O2. I'll try O1 or O0 version. Or maybe LLVM.

Probably I incorrectly compiled some dylibs, or incorrectly signed APP (no errors after checking). I'll try to create more simple tests tomorrow.


Chris,

Even now FPC speed for aarch64 is very good for me. But your results of speed are very impressive. It would great to have these optimizations included for FPC in future.

I'll support FPC developers on Patreon. Really good idea. Thanks for reminding.
TinyPortal © 2005-2018