xcodebuild ACTIVE_COMPILATION_CONDITIONS does not override target's ACTIVE_COMPILATION_CONDITIONS - swift

We are trying to use xcodebuild to build our frameworks, instead of using manual Xcode IDE running buttons. The issue is that in our framework we use ACTIVE_COMPILATION_CONDITIONS, which have several values. Those values are then used to check at runtime if the particular framework is integrated, like checking for Sentry:
#if SENTRY_AVAILABLE
import Sentry
#endif
The problem is that, for some builds, we need to override our project settings, specifically ACTIVE_COMPILATION_CONDITIONS. However, after the following script successfully executes, the Xcode still does not override our provided ACTIVE_COMPILATION_CONDITIONS with defined in the project.
The script:
xcodebuild -workspace project.xcworkspace -scheme SDKNR1 ONLY_ACTIVE_ARCH=NO
EXCLUDED_ARCHS=arm64 ACTIVE_COMPILATION_CONDITIONS=SENTRY_AVAILABLE -configuration
release -derivedDataPath $PROJECT_DIR/../simulators/SDKNR1 -sdk iphonesimulator
ENABLE_BITCODE=YES BITCODE_GENERATION_MODE=bitcode OTHER_CFLAGS="-fembed-bitcode" clean build
As you can see we define ACTIVE_COMPILATION_CONDITIONS=SENTRY_AVAILABLE, however it will not override target's (SDKNR1) project settings. Suppose, SDKNR1 does not have any ACTIVE_COMPILATION_CONDITIONS. We expected that xcodebuild command would override target's ACTIVE_COMPILATION_CONDITIONS and would include SENTRY_AVAILABLE
Would welcome any ideas, or perhaps it is not possible?

The proper build setting key is "SWIFT_ACTIVE_COMPILATION_CONDITIONS"
You can double check this by using the command and verifying the key exists:
xcodebuild -showBuildSettings <project/scheme/target/configuration flags>
Results from -showBuildSettings (truncated, for RELEASE_CONDITION2 set in the Xcode project settings for release build [for some reason debug wont show]):
.....
SUPPORTS_TEXT_BASED_API = NO
SWIFT_ACTIVE_COMPILATION_CONDITIONS = RELEASE_CONDITION2
SWIFT_COMPILATION_MODE = wholemodule
.....
In build log, you should see (as example here, setting RELEASE_CONIDTION2, also note that the ACTIVE_COMPLIATION_CONIDTIONS gets translated into -D parameters for swiftc):
Build settings from command line:
.....
SDKROOT = iphoneos14.5
SWIFT_ACTIVE_COMPILATION_CONDITIONS = RELEASE_CONDITION2
.....
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler .....
.....
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc <most compiler options removed> -DRELEASE_CONDITION2
Above is all with Xcode 12.5

Related

How to determine configuration in Swift code using Swift Package Manager

I'm creating an application using Swift Package Manager and I need to know the configuration of which the project was built under, i.e Debug or Release. I'm trying to stay away from using the .xcodeproj file. Please, someone let me know if this is possible. I'll paste a simple example below, but just know if there's a better way to handling configuration besides the code below, please submit as answer.
Example:
// main.swift
#if DEBUG
print("Im in Debug!!")
#else
print("Im in Release!!")
#endif
As of Swift 3.1, the Package Manager doesn't offer the option to customize build settings in the Package.swift file (this feature is part of the team's roadmap for Swift 4). However, you can use the -Xswiftc flag to pass custom build settings to the compiler when you invoke swift build or swift test.
To set the DEBUG flag in debug mode, invoke swift build like this:
swift build --configuration debug -Xswiftc "-D" -Xswiftc "DEBUG"
And for release builds you would do the usual:
swift build --configuration release
There is also -Xlinker and Xcc to pass flags to the linker and C compiler, respectively.

"Module was not compiled for testing" error when using Swift Package Manager

I created a Swift library with swift package init --type library and generated an Xcode project with swift package generate-xcodeproj.
Now I'm trying to run the Test scheme in Xcode. It prints following error:
Module '<title>' was not compiled for testing
However when I run swift build and swift test in terminal, it works fine.
I have ENABLE_TESTABILITY set to YES in all of the targets. I didn't change anything in the project except this. How can I make Xcode perform unit testing?
You need to set the "Enable Testability" to Yes in build setting over your "Main Target"
I was having this issue today, it seems like #testable cannot be used with projects generated by Swift Package Manager.
Removing #testable from my import statements solved this issue. Of course, this means we can only test the public interface of our modules.
Xcode -> Product -> Scheme -> Edit Scheme
Select the Info tab.
Set the following -
Build Configuration: Debug
Add a check mark to Debug executable
Tested with Xcode 12.4(12D4e) and iOS 14.1 deployment target.

Why is Eclipse ignoring my Cross GCC tool prefix?

I am attempting to build a sample project using the ARM Embedded GCC toolchain; for this, I am using Eclipse's internal builder.
In the settings, Project Properties -> C/C++ Build -> Settings -> Tool Settings -> Cross Settings, Prefix is set to arm-none-eabi- and Path is set to the path of the ARM toolchain (C:\Program Files (x86)\GNU Tools ARM Embedded\4.7 2012q4\bin).
When I attempt to build the project, I get something that looks like this:
17:58:13 **** Incremental Build of configuration Debug for project template_test ****
Info: Internal Builder is used for build
gcc -IC:/foo/Libraries/STM32F0xx_StdPeriph_Driver/inc -IC:/foo/Libraries/CMSIS/Device/ST/STM32F0xx/Include -IC:/foo/Libraries/CMSIS/Include -O0 -g3 -Wall -c -fmessage-length=0 -o "Libraries\\STM32F0xx_StdPeriph_Driver\\src\\stm32f0xx_adc.o" "..\\Libraries\\STM32F0xx_StdPeriph_Driver\\src\\stm32f0xx_adc.c"
Cannot run program "gcc": Launching failed
... and then an error about how gcc is not found in my path. Which, of course, it is not. There is in my path, however, an arm-none-eabi-gcc.exe, but for some reason, Eclipse is not inclined to run that one.
Why not?
I have discovered that if I change the "Command" for "Cross GCC Compiler" (Project Properties -> C/C++ Build -> Settings -> Tool Settings -> Cross GCC Compiler -> Command) to "gc" (from "gcc") then Eclipse attempts to run "arm-none-eabi-gc" instead of "gc". I feel like that's an important clue, but I don't understand it.
Its looks like an update problem. When I include the prefix in the command, it then tried to use the prefix twice. I removed the prefix from the command and now it works as intended.
I had a similar problem. I added the path to the prefix and it seemed to work. You could also try using a short windows file path: c:/Progra~2/ ...

Building BlackBerry 10 native application package from command line

I have created a native HelloWorld application for BlackBerry 10 using BB NDK 10.0.9 and running it inside a simulator. I use Momentics IDE and can easily compile and deploy my application.
However, i want to setup an automated build process from the command line. I was able to compile ELF binary using makefile. But i am stuck in creation of .bar file.
I try to build .bar with the command:
blackberry-airpackager.bat -package HelloWorld2.bar application.xml
but the target .bar does not contain my native binary.
What am i doing wrong?
There is a special packager for native applications: blackberry-nativepackager
This code did the trick:
blackberry-nativepackager.bat -package HelloWorld2.bar bar-descriptor.xml
And yet another configuration was added to bar-descriptor.xml besides the simulator:
<configuration id="com.qnx.qcc.toolChain.2121420202" name="Device-Release">
<platformArchitecture>armle-v7</platformArchitecture>
<asset path="arm/o.le-v7/HelloWorld" entry="true" type="Qnx/Elf">HelloWorld</asset>
</configuration>

Xcode: Build architecture specific per file compiler build settings

in my iPhone project I am using some inline asm, which is excluded if the target architecture is the device and not the simulator.
Since some of the inline asm code is arm only and not thumb I need to specify the c flag -marm when compiling it for the iPhone, since it otherwise trys to compile the code with the thumb instructions.
And here is the problem if I enter the -marm flag in the file specific build setting, gcc outputs an error if I compile for the simulator:
cc1obj: error: unrecognized command line option "-marm"
Is there a way to pass this option only if the target architecture is arm?
I know you can do it with the global c flags, but I dont want to compile my whole project with the -marm flag. I want only a few .m files to be -marm.
Thanks and greetings, Kim
OK I found a solution for the issue.
Here is the comment I added to the code:
// the asm code only works with arm not with thumb,
// so if you compile it and gcc trys to compile it as thumb
// you will get an error.
// to make gcc compile the file as arm and not thumb you need
// to add -marm to the files compiler config (select the file
// and press cmd + i and select the build tab and enter there
// the problem is that if you try to compile for the simulator
// it will fail, because intel gcc doesnt know the flat -marm.
// To solve this add a new "User defined setting" in your targets
// build settings with the name use_marm and give it the value ""
// then add a build setting condition and select Any iPhone OS
// Device and give it the value "-marm"
// In your file's compiler flags add $use_marm
// If you build for the device it will add -marm and if you
// build for the simulator it wont.