Kolos65 / Mockable

A Swift macro driven auto-mocking library.
MIT License
248 stars 18 forks source link

App doesn't compile with generic destination on xcodebuild #11

Open emadhegab opened 10 months ago

emadhegab commented 10 months ago

I try to compile my app using this command xcodebuild -scheme 'MyApp' -sdk 'iphonesimulator' -destination 'generic/platform=iOS Simulator'

but it gives me error always

protocos/MyAppService.swift:5:17: external macro implementation type 'MockableMacro.MockableMacro' could not be found for macro 'Mockable()'

It will run fine if changed the destination into -destination 'platform=iOS Simulator,name=iPhone' but that will prevent me from using the .app file it generates in the E2E testing i have.

Kolos65 commented 10 months ago

I can repro this on an example project, will update you if I find anything.

Kolos65 commented 10 months ago

Not sure why, but what I have found so far is that if you omit the -sdk 'iphonesimulator' flag, it compiles: xcodebuild -scheme 'MyApp' -destination 'generic/platform=iOS Simulator' Are you sure you need to specify the base SDK explicitly?

emadhegab commented 10 months ago

I tried. but it crash when dragging the .app to simulator and try to run it. i think without sdk it takes the default which is probably the real device

Kolos65 commented 7 months ago

@emadhegab I will close this for now due to inactivity, will reopen if needed.

carlossolana-aily commented 3 months ago

Someting similar is happening to me when archiving in the CI (GitHub Actions, macos13, Xcode 15.0.1, but also happens in macos14 and Xcode 15.4):

** ARCHIVE FAILED **

The following build commands failed:
    ComputeTargetDependencyGraph

If I remove Mockable from all module dependencies, comment imports and macros, then it works. The command looks like:

xcodebuild -workspace MyProject.xcworkspace -scheme MyScheme -configuration MyConfig -destination 'generic/platform=iOS' -skipPackagePluginValidation clean archive

The other dependencies I use are:

        .package(url: "https://github.com/hmlongco/Factory", exact: "2.3.2"),
        .package(url: "https://github.com/Kolos65/Mockable", exact: "0.0.9"),
        .package(url: "https://github.com/realm/SwiftLint", exact: "0.55.1")

Do you have any clue about what can be going on? I really like this library, I'd love to make it work :)

carlossolana-aily commented 3 months ago

A minor finding: If I leave my codebase like this:

#if canImport(Mockable)
import Mockable
#endif

#if canImport(Mockable)
@Mockable
#endif
protocol BlaBla {

And my Package.swift like this:

dependencies: [
        .package(path: "../PackageA"),
        .package(path: "../PackageB"),
        .package(path: "../PackageC"),
        .package(path: "../PackageD"),
        .package(url: "https://github.com/hmlongco/Factory", exact: "2.3.2"),
        .package(url: "https://github.com/Kolos65/Mockable", exact: "0.0.9"),
        .package(url: "https://github.com/realm/SwiftLint", exact: "0.55.1")
    ],
    targets: [
        .target(name: "MyPackage",
                dependencies: ["PackageA", "PackageB", "Factory", "PackageC", "PackageD"/*, .product(name: "Mockable", package: "Mockable")*/],
                path: "Sources",
                swiftSettings: [.define("MOCKING", .when(configuration: .debug))],
                plugins: [.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLint")]),
        .testTarget(name: "MyPackageTests", dependencies: ["MyPackage", .product(name: "MockableTest", package: "Mockable")]),
    ]

Then it still works on CI, because the produced product is not included in the target, and at the same time is "easy" to activate it (just uncomment that part) without changing the actual codebase.

Still trying to figure out the cause of this issue, I'll use this as a temporary workaround.

Kolos65 commented 3 months ago

@carlossolana-aily Have you tried adding -skipMacroValidation to the xcodebuild command?

carlossolana-aily commented 3 months ago

No, I didn't! Now I reverted everything and it works! Thank you very much! :D

PowerOfCreation commented 1 month ago

@Kolos65 I have the same problem and I need to build for iphonesimulator. Adding -skipMacroValidation to the xcodebuild command doesn't help unfortunately.

error: external macro implementation type 'MockableMacro.MockableMacro' could not be found for macro 'Mockable()'; '..../(Development)-iphonesimulator/MockableMacro' produced malformed response
public protocol MyServiceName {
                ^
.../build/derived_data/SourcePackages/checkouts/Mockable/Sources/Mockable/Macro/MockableMacro.swift:41:14: note: 'Mockable()' declared here
public macro Mockable() = #externalMacro(module: "MockableMacro", type: "MockableMacro")
Jose-Luis-Nunez commented 1 month ago

i have the same issue like emadhegab and -skipMacroValidation did not help, would be very nice if someone can support :-)