Xcode 12 build on M1 Mac mini

I used the migration assistant to migrate from a 2014 MacBook Air to a M1 chip Mac Mini. Part of the migration moved my Xcode projects 11.3.1 to the new Mac mini. I subsequently downloaded Xcode 12.3 to the Mac Mini and used it to build the projects. Three of the projects are static libraries and one is the consumer of the libraries.

The builds for the static libraries uses a Run Script with XCodeBuild for iphoneos and iphonesimulator and then lipo to build a universal library. Finally the universal library is copied to the consumer.

On Xcode12 Mac mini I was getting errors from lipo stating that both have arm64 slices and could not build. I used ONLYACTIVEARCH=NO and Yes in various efforts to try to remove the arm64 from the iphoneos to no avail. Also the build settings was sticky with exclude architectures and would not delete entries.

After a few very frustrating days combing the web for solutions that mainly dealt with excluding arm64 from the simulator I gave up and just built a iphoneos .a file and a iphonesimulator .a file and moved them to the consumer project. This worked so I created a "sim" version of my consumer prjoject and a iphoneos debug version. This worked and even better because of the -swift.h headers for both simulator and iphoneos.

But I am now unable to copy the files in my Run Script as it gives me "permission denied" errors on my cp command. I think it is because the ouput files are marked read only as well as the directories created in the build folders. This may be a migration issue and what user runs Xcode. Apparently not my userid (which is Admin and the installer of Xcode 12).

Scripting on Linux is not my strong suit so maybe some errors in the copy but the Xcodebuild issue with arm64 may be a bug. However, the copy worked fine on the Macbook air Xcode 11.3.1.

One possible issue is The MacBook Air was given to me by my son and it is still called name as owner. This may the permissions issues as the projects migrated over to the new Mac mini.

Below is the pervious Run Script and the new run script:

Xcode 11.3.1 Run Script on intel Mac Air

define output folder environment variable

UNIVERSALOUTPUTFOLDER=${BUILDDIR}/${CONFIGURATION}-universal

Step 1. Build Device and Simulator versions

xcodebuild -target AppLibrary ONLYACTIVEARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILDDIR="${BUILDDIR}" BUILDROOT="${BUILDROOT}"
xcodebuild -target AppLibrary -configuration ${CONFIGURATION} -sdk iphonesimulator -arch x8664 -arch i386 -arch armv7 -arch armv7s -arch arm64 BUILDDIR="${BUILDDIR}" BUILDROOT="${BUILDROOT}"
echo UNIVERSAL
OUTPUTFOLDER

make sure the output directory exists

mkdir -p "${UNIVERSALOUTPUTFOLDER}"

Step 2. Create universal binary file using lipo

lipo -create -output "${UNIVERSAL
OUTPUTFOLDER}/lib${PROJECTNAME}.a" "${BUILDDIR}/${CONFIGURATION}-iphoneos/lib${PROJECTNAME}.a" "${BUILDDIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECTNAME}.a"

Last touch. copy the header files. Just for convenience

cp -R "${BUILD
DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSALOUTPUTFOLDER}/"
cp -R "/Users/davidsmaltz/Documents/afsLibrary/AppLibrary/Build/Products/Debug-universal/" "/Users/davidsmaltz/Documents/afsLibrary/MyApp/Debug-universal/"

New Mac mini Xcode 12 Run Script

xcodebuild -target afsViewControlManager ONLY
ACTIVEARCH=NO  -configuration ${CONFIGURATION} -sdk iphoneos  BUILDDIR="${BUILDDIR}" BUILDROOT="${BUILDROOT}"

 xcodebuild -target afsViewControlManager  -configuration ${CONFIGURATION} -sdk iphonesimulator BUILD
DIR="${BUILDDIR}" BUILDROOT="${BUILD_ROOT}"

 cp -R

"/Users/davidsmaltz/Documents/afsLibrary/afsViewControlManager/Build/Products/Debug-iphonesimulator/libafsViewControlManager.a"

"/Users/davidsmaltz/Documents/afsLibrary/MyAppSim/Debug-universal/"

"/Users/davidsmaltz/Documents/afsLibrary/afsViewControlManager/Build/Products/Debug-iphoneos/libafsViewControlManager.a"

"/Users/davidsmaltz/Documents/afsLibrary/MyApp/Debug-universal/"

Thank You

Replies

Also to add more information, below is what appears in the project pane on right for the Library consumer project along with NO EDITOR to the right of this and no Build Settings:

// !$*UTF8*$!

{

archiveVersion = 1;

classes = {

};

objectVersion = 46;

objects = {



/* Begin PBXBuildFile section */

1855167821A5E0BD00E4AA73 /* LibraryClasses.m in Sources */ = {isa = PBXBuildFile; fileRef = 1855167721A5E0BD00E4AA73 /* LibraryClasses.m */; };

18B17C0E21F0E63B00BED975 /* SwiftFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18B17C0D21F0E63B00BED975 /* SwiftFile.swift */; };

18DB1F342195D7180045EA8D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4925203121120B0B00AF7C8D /* AppDelegate.m */; };

18DB1F352195D71D0045EA8D /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4925203421120B0B00AF7C8D /* ViewController.m */; };

18DB1F362195D7270045EA8D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4925202E21120B0B00AF7C8D /* main.m */; };

18DB1F382195D74C0045EA8D /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 18DB1F372195D74C0045EA8D /* Default-568h@2x.png */; };

18F1FB5E2201FB8A00D866B8 /* libCustomSwiftLibrary.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 18F1FB5D2201FB8A00D866B8 /* libCustomSwiftLibrary.a */; };

18F1FB602201FB9900D866B8 /* libAppLibrary.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 18F1FB5F2201FB9900D866B8 /* libAppLibrary.a */; };

18F1FB622201FBB900D866B8 /* libafsViewControlManager.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 18F1FB612201FBB900D866B8 /* libafsViewControlManager.a */; };

4925203821120B0B00AF7C8D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4925203621120B0B00AF7C8D /* Main.storyboard */; };

4925203A21120B0B00AF7C8D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4925203921120B0B00AF7C8D /* Assets.xcassets */; };

4925203D21120B0B00AF7C8D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4925203B21120B0B00AF7C8D /* LaunchScreen.storyboard */; };

4925204821120B0B00AF7C8D /* GenAppTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4925204721120B0B00AF7C8D /* GenAppTests.m */; };

4925205321120B0B00AF7C8D /* GenAppUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4925205221120B0B00AF7C8D /* GenAppUITests.m */; };

/* End PBXBuildFile section */






Along with a lot more that would not fit here



Here is the workaround:

In the Xcode Build Phases Run Script -

xcodebuild -target AppLibrary ONLYACTIVEARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos  BUILDDIR="${BUILDDIR}" BUILDROOT="${BUILDROOT}"


xcodebuild -target AppLibrary -configuration ${CONFIGURATION} -sdk iphonesimulator BUILDDIR="${BUILDDIR}" BUILDROOT="${BUILDROOT}"

Then build a simulator version of the project that uses the library and set the Frameworks and library path user header in build settings to point to the location of the iphonesimulator output of the above RunScirpt xcodebuild. This allows the simulator to run every time during development and debug without having to copy the files or build a universal lib. Don't forget to use finder to copy changes to the headers .h. files and move the correct simulator -Swift.h file to the project.

In the Device testing and distribution version of the product use Finder to move the current version of the iphoneos library from RunScript xcodebuild to the Frameworks and keep the user search paths local in build settings. Copy the headers .h and device version of -Swift.h file.

This works to get around not being able to copy files out of RunScript in Xcode 12 which may be a bug. Also cannot use LIPO to build universal library which also may be a bug.