Recent

Author Topic: Apple Developer Transition Kit  (Read 4122 times)

Igor Kokarev

  • Full Member
  • ***
  • Posts: 198
Re: Apple Developer Transition Kit
« Reply #45 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.
« Last Edit: July 24, 2020, 09:19:44 am by Igor Kokarev »

Igor Kokarev

  • Full Member
  • ***
  • Posts: 198
Re: Apple Developer Transition Kit
« Reply #46 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.  

ChrisR

  • Full Member
  • ***
  • Posts: 158
Re: Apple Developer Transition Kit
« Reply #47 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.

Igor Kokarev

  • Full Member
  • ***
  • Posts: 198
Re: Apple Developer Transition Kit
« Reply #48 on: July 24, 2020, 07:05:34 pm »
Chris,

Thanks! I hope it will be fixed now.

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 751
Re: Apple Developer Transition Kit
« Reply #49 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).

Igor Kokarev

  • Full Member
  • ***
  • Posts: 198
Re: Apple Developer Transition Kit
« Reply #50 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.

Igor Kokarev

  • Full Member
  • ***
  • Posts: 198
Re: Apple Developer Transition Kit
« Reply #51 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.

Igor Kokarev

  • Full Member
  • ***
  • Posts: 198
Re: Apple Developer Transition Kit
« Reply #52 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.

ChrisR

  • Full Member
  • ***
  • Posts: 158
Re: Apple Developer Transition Kit
« Reply #53 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.

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 751
Re: Apple Developer Transition Kit
« Reply #54 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.

Igor Kokarev

  • Full Member
  • ***
  • Posts: 198
Re: Apple Developer Transition Kit
« Reply #55 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.

Igor Kokarev

  • Full Member
  • ***
  • Posts: 198
Re: Apple Developer Transition Kit
« Reply #56 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

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 751
Re: Apple Developer Transition Kit
« Reply #57 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.

Igor Kokarev

  • Full Member
  • ***
  • Posts: 198
Re: Apple Developer Transition Kit
« Reply #58 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?
« Last Edit: July 30, 2020, 09:53:53 am by Igor Kokarev »

Igor Kokarev

  • Full Member
  • ***
  • Posts: 198
Re: Apple Developer Transition Kit
« Reply #59 on: July 30, 2020, 10:07:55 pm »

 

TinyPortal © 2005-2018