How to build an universal application in PB
Posted: Tue Jun 20, 2023 9:34 am
Hello,
It is inconvenient to have to distribute your applications in two copies depending on whether they are intended for Apple Silicon or Intel. Therefore, as Apple has always offered the possibility to generate FatBinary executables, here's how it works for PureBasic:
First, you need to understand what a bundle is. A bundle is an executable folder that ends with .app and contains the Content subfolder. Inside the Content subfolder, there is another subfolder named MacOS, which contains the executable.
Good news, this is not compiler-specific but rather an assembly of 2 executables, so it works for all compilers.
You need to create 2 versions of the executable (with slightly different names), one for Intel and the other for ARM (so you need both versions of PureBasic).
You need to merge them using the following command in a terminal:
[syntax]lipo -create path_to_ARM_executable -arch x86_64 path_to_Intel_executable -output path_to_universal_executable[/syntax]
Then, take one of the two bundles (file.app), display its contents, and replace the contents of the MacOS folder with the new executable.
Next, you need to edit the info.plist file located in the package .../ApplicationName.app/Content/info.plist and insert the following into the dict key:
[syntax]
<key>LSArchitecturePriority</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
[/syntax]
Example:
It is inconvenient to have to distribute your applications in two copies depending on whether they are intended for Apple Silicon or Intel. Therefore, as Apple has always offered the possibility to generate FatBinary executables, here's how it works for PureBasic:
First, you need to understand what a bundle is. A bundle is an executable folder that ends with .app and contains the Content subfolder. Inside the Content subfolder, there is another subfolder named MacOS, which contains the executable.
Good news, this is not compiler-specific but rather an assembly of 2 executables, so it works for all compilers.
You need to create 2 versions of the executable (with slightly different names), one for Intel and the other for ARM (so you need both versions of PureBasic).
You need to merge them using the following command in a terminal:
[syntax]lipo -create path_to_ARM_executable -arch x86_64 path_to_Intel_executable -output path_to_universal_executable[/syntax]
Then, take one of the two bundles (file.app), display its contents, and replace the contents of the MacOS folder with the new executable.
Next, you need to edit the info.plist file located in the package .../ApplicationName.app/Content/info.plist and insert the following into the dict key:
[syntax]
<key>LSArchitecturePriority</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
[/syntax]
Example:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- Other keys and values in the Info.plist file -->
...
<key>LSArchitecturePriority</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<!-- Other keys and values in the Info.plist file -->
...
</dict>
</plist>