Skip to content

[Macros] Add executable compiler plugin support library #1359

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

Merged
merged 7 commits into from
Feb 28, 2023

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Feb 23, 2023

SwiftCompilerPlugin is a helper library to write an executable compiler plugin.

Usage:

import SwiftCompilerPlugin
import SwiftSyntaxMacros

@main
struct MyPlugin: CompilerPlugin {
  var providingMacros: [Macro.Type] = [MyMacro.self]
}

struct MyMacro: ExpressionMacro {
  ...
}

@rintaro rintaro requested a review from ahoppen as a code owner February 23, 2023 08:40
@rintaro rintaro marked this pull request as draft February 23, 2023 18:50
@rintaro rintaro force-pushed the compiler-plugin-support branch 2 times, most recently from e79ecb1 to f29f3ce Compare February 23, 2023 20:09
@rintaro
Copy link
Member Author

rintaro commented Feb 23, 2023

swiftlang/swift#63793
@swift-ci Please test

@rintaro rintaro force-pushed the compiler-plugin-support branch from f29f3ce to e275899 Compare February 23, 2023 22:24
@rintaro
Copy link
Member Author

rintaro commented Feb 23, 2023

@swift-ci Please test

@rintaro rintaro force-pushed the compiler-plugin-support branch from e275899 to f302774 Compare February 24, 2023 03:49
@rintaro
Copy link
Member Author

rintaro commented Feb 24, 2023

@swift-ci Please test

@rintaro
Copy link
Member Author

rintaro commented Feb 24, 2023

swiftlang/swift#63888
@swift-ci Please test

@rintaro rintaro force-pushed the compiler-plugin-support branch from f302774 to 1561e76 Compare February 24, 2023 20:36
@rintaro
Copy link
Member Author

rintaro commented Feb 24, 2023

swiftlang/swift#63888
@swift-ci Please test

@rintaro rintaro marked this pull request as ready for review February 24, 2023 23:08
@rintaro
Copy link
Member Author

rintaro commented Feb 24, 2023

@ahoppen Let me know if you have any concern with the build-script.py changes.

@rintaro
Copy link
Member Author

rintaro commented Feb 25, 2023

@swift-ci Please test

@rintaro rintaro force-pushed the compiler-plugin-support branch from 473bc7e to afff5aa Compare February 25, 2023 01:45
@rintaro
Copy link
Member Author

rintaro commented Feb 25, 2023

@swift-ci Please test

@rintaro rintaro force-pushed the compiler-plugin-support branch from 70ec0e4 to 9f40b5c Compare February 25, 2023 04:13
@rintaro
Copy link
Member Author

rintaro commented Feb 25, 2023

@swift-ci Please test


// Local function to expand a member atribute macro once we've opened up
// the existential.
func expandMemberAttributeMacro<Node: DeclGroupSyntax>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn’t the content of this just be a trailing closure to _openExistential? Same below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rintaro rintaro force-pushed the compiler-plugin-support branch from 089cad0 to 78ef801 Compare February 27, 2023 22:04
@rintaro
Copy link
Member Author

rintaro commented Feb 27, 2023

swiftlang/swift#63952
@swift-ci Please test

'SwiftCompilerPlugin' is a helper library to write an executable
compiler plugin.

Usage:

  import SwiftCompilerPlugin
  import SwiftSyntaxMacros

  @main
  struct MyPlugin: CompilerPlugin {
    var providingMacros: [Macro.Type] = [MyMacro.self]
  }

  struct MyMacro: ExpressionMacro {
    ...
  }
There's no reason to do so, and some how plugin test fails with:

  ```
  dyld: lazy symbol binding failed: can't resolve symbol _swift_task_create
  in /Users/ec2-user/.../ExamplePlugin because dependent dylib
  @rpath/libswift_Concurrency.dylib could not be loaded
  ```
@rintaro rintaro force-pushed the compiler-plugin-support branch from 78ef801 to 01c125d Compare February 28, 2023 03:21
@rintaro rintaro force-pushed the compiler-plugin-support branch from 01c125d to 69230a2 Compare February 28, 2023 03:21
@rintaro
Copy link
Member Author

rintaro commented Feb 28, 2023

swiftlang/swift#63958
@swift-ci Please test

@rintaro
Copy link
Member Author

rintaro commented Feb 28, 2023

swiftlang/swift#63958
@swift-ci Please test macOS

@rintaro rintaro force-pushed the compiler-plugin-support branch from 69230a2 to 4f4b873 Compare February 28, 2023 07:54
@rintaro
Copy link
Member Author

rintaro commented Feb 28, 2023

swiftlang/swift#63958
@swift-ci Please test

@rintaro rintaro merged commit 857111a into swiftlang:main Feb 28, 2023
neonichu added a commit to swiftlang/swift-package-manager that referenced this pull request Mar 1, 2023
This adds support for building macros as executables (see swiftlang/swift-syntax#1359).

Right now, this requires adding a package dependency on swift-syntax and corresponding product dependencies to the macro itself which makes testing difficult, so `BUILD_MACROS_AS_DYLIBS` is kept as the default mode.
neonichu added a commit to swiftlang/swift-package-manager that referenced this pull request Mar 1, 2023
This adds support for building macros as executables (see swiftlang/swift-syntax#1359).

Right now, this requires adding a package dependency on swift-syntax and corresponding product dependencies to the macro itself which makes testing difficult, so `BUILD_MACROS_AS_DYLIBS` is kept as the default mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants