swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
66.85k stars 10.3k forks source link

[SR-15232] ReactiveObjC: error: 'TARGET_OS_OSX' is not defined, evaluates to 0 [-Werror,-Wundef-prefix=TARGET_OS_] #57554

Open benlangmuir opened 2 years ago

benlangmuir commented 2 years ago
Previous ID SR-15232
Radar rdar://83420693
Original Reporter @benlangmuir
Type Bug

Attachment: Download

Environment Swift 5.5 from swift.org (with Xcodes's clang it is a warning).
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 2f367cbeee8b0f06e0fad0c33591725a

Issue Description:

Jenkins URL: https://ci.swift.org/job/swift-main-source-compat-suite/6220

NSObject+RACAppKitBindings.m:1:6: error: 'TARGET_OS_OSX' is not defined, evaluates to 0 [-Werror,-Wundef-prefix=TARGET_OS_]
#if (TARGET_OS_OSX)

This is affecting many other files in this project as well. The consequence is that these macros are always undefined, causing code to not be compiled that ought to. The fix is to add #import <TargetConditionals.h> to any files using these macros.

I believe this problem was hidden before, because we were defaulting to this being a warning instead of an error.

justice-adams-apple commented 1 year ago

Hi @igor-makarov 👋

This is failing to build in our source compatibility suite due to the fact that with Xcode's clang this is a warning, but with open source clang (including the clang in our swift.org toolchain) it's an error by default.

We wanted to bring this error to your attention. I was able to confirm that adding the appropriate #import <TargetConditionals.h> statements does in fact fix the build.

If you decide to update your project, I would recommend updating the project definition in the source compat suite. This will allow your project to be continuously tested with compiler changes properly. https://github.com/apple/swift-source-compat-suite/blob/main/projects.json#L2368

igor-makarov commented 4 months ago

So here's the issue: while SwiftPM-Packages/ReactiveObjC.swiftpm is my repo, it merely exists to reference a legacy library located in https://github.com/ReactiveCocoa/ReactiveObjC and link it as a Swiff PM package.

The legacy library does not belong to me and I do not see a path forward where someone updates it for this specific concern.

FYI @zixu-w @xymus @benlangmuir can I do something about this that doesn't involve changes to the legacy library? Perhaps make some changes to the cSettings?

benlangmuir commented 4 months ago

Adding -Wno-error=undef-prefix to the compilation will demote the error to a warning, but I don't know if swiftpm has a way to specify that without using unsafeFlags. @MaxDesiatov?

MaxDesiatov commented 4 months ago

Adding -Wno-error=undef-prefix to the compilation will demote the error to a warning, but I don't know if swiftpm has a way to specify that without using unsafeFlags. @MaxDesiatov?

Not at the moment, unfortunately.