Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] No HelperCoder generated when check compilation condition #82

Open
1 task done
mo5tone opened this issue May 9, 2024 · 6 comments
Open
1 task done
Labels
enhancement New feature or request

Comments

@mo5tone
Copy link

mo5tone commented May 9, 2024

Describe the bug
Below code works well.

working code
@Codable
@CodedAs<String?>
@CodedAt("operation")
protocol ResponseAttributes {}

@Codable
struct Response {
    @CodedIn("data")
    let id: String
    @CodedIn("data")
    let type: String
    @CodedIn("data")
    @CodedBy(ResponseAttributesCoder())
    let attributes: ResponseAttributes
}

@Codable
struct RegistrationAttributes: ResponseAttributes, DynamicCodable {
    static var identifier: DynamicCodableIdentifier<String?> { .one("REGISTRATION") }
    let id: String
    @CodedAt("status-code")
    let statusCode: String
    let operation: String
}
@Codable
struct VerificationAttributes: ResponseAttributes, DynamicCodable {
    static var identifier: DynamicCodableIdentifier<String?> { .one(nil) }
    let id: String
    let operation: String?
    let expiresIn: UInt
    @CodedAt("xxx-token")
    let xxxToken: String
    @CodedAt("yyy-token")
    let yyyToken: String
}

But the ResponseAttributesCoder will be missing if add #if SOME_SWIFT_ACTIVE_COMPILATION_CONDITION.

Xcode say 'Cannot find 'AnonymousAttestationResponseAttributesCoder' in scope'.

failed to work
// Have set the `SOME_SWIFT_ACTIVE_COMPILATION_CONDITION` in `swiftSettings` from `Package.swift`.
#if SOME_SWIFT_ACTIVE_COMPILATION_CONDITION
@Codable
@CodedAs<String?>
@CodedAt("operation")
protocol ResponseAttributes {}

@Codable
struct Response {
    @CodedIn("data")
    let id: String
    @CodedIn("data")
    let type: String
    @CodedIn("data")
    @CodedBy(ResponseAttributesCoder())
    let attributes: ResponseAttributes
}

@Codable
struct RegistrationAttributes: ResponseAttributes, DynamicCodable {
    static var identifier: DynamicCodableIdentifier<String?> { .one("REGISTRATION") }
    let id: String
    @CodedAt("status-code")
    let statusCode: String
    let operation: String
}
@Codable
struct VerificationAttributes: ResponseAttributes, DynamicCodable {
    static var identifier: DynamicCodableIdentifier<String?> { .one(nil) }
    let id: String
    let operation: String?
    let expiresIn: UInt
    @CodedAt("xxx-token")
    let xxxToken: String
    @CodedAt("yyy-token")
    let yyyToken: String
}
#endif

To Reproduce
Steps to reproduce the behavior:

  1. Create an empty swift package
  2. Add MetaCodable to dependencies
  3. Copy and paste the code above
  4. commnad + B

Expected behavior
Compilation condition check shouldn't fail plugin or macro.

Environment (please complete the following information, remove ones not applicable):

  • OS: macOS
  • Version 13.6.6
  • Xcode 15.2
  • Swift 5.9.2
@mo5tone mo5tone added the bug Something isn't working label May 9, 2024
@soumyamahunt
Copy link
Contributor

@mo5tone build tool plugins don't have access to build settings, hence you are seeing no HelperCoder being generated. What is the use case you are trying to achieve here?

@soumyamahunt soumyamahunt removed the bug Something isn't working label May 13, 2024
@soumyamahunt soumyamahunt changed the title [Bug] No HelperCoder generated when check compilation condition [Feature Request] No HelperCoder generated when check compilation condition May 13, 2024
@mo5tone
Copy link
Author

mo5tone commented May 14, 2024

@mo5tone build tool plugins don't have access to build settings, hence you are seeing no HelperCoder being generated. What is the use case you are trying to achieve here?

I am building a private swift package to deliver some common functionalities across projects.
Some projects use non-standard dependency management like tuist which map swift package to project but cannot handle macro and plugin properly.

So I want to use compilation condition to skip usage of macro and plugin on compile time when my package is converted by tuist and does not affect other projects that use swift package manager.

@soumyamahunt soumyamahunt added the enhancement New feature or request label May 30, 2024
@Gray-Wind
Copy link

There is a new module for swift-syntax and it seems that with it it would be possible to respect compilation conditions swiftlang/swift-syntax#1816

@mo5tone
Copy link
Author

mo5tone commented Aug 29, 2024

I am building a private swift package to deliver some common functionalities across projects. Some projects use non-standard dependency management like tuist which map swift package to project but cannot handle macro and plugin properly.

So I want to use compilation condition to skip usage of macro and plugin on compile time when my package is converted by tuist and does not affect other projects that use swift package manager.

I found that tuist can work well with another macro package but not MetaCodable.

I have raised tuist/tuist#6579.

@soumyamahunt
Copy link
Contributor

There is a new module for swift-syntax and it seems that with it it would be possible to respect compilation conditions swiftlang/swift-syntax#1816

@Gray-Wind this feature seems to be under active development and hasn't been released yet, will have a look on how this could possibly solve this issue once it is released.

@soumyamahunt
Copy link
Contributor

I am building a private swift package to deliver some common functionalities across projects. Some projects use non-standard dependency management like tuist which map swift package to project but cannot handle macro and plugin properly.

@mo5tone Can you try just including MetaCodable as a Swift package instead of mapping into project. You can find the integration example in the Examples folder of this repo. I think the internal hacks being done by tuist to map a Swift package to project is failing here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants