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

Enable original package patching using swift package mirroring #5

Open
lyzkov opened this issue Aug 22, 2024 · 7 comments
Open

Enable original package patching using swift package mirroring #5

lyzkov opened this issue Aug 22, 2024 · 7 comments

Comments

@lyzkov
Copy link

lyzkov commented Aug 22, 2024

As we discussed in swift-syntax, a top-level package dependency graph can be patched with:

swift package config set-mirror --original https://github.com/swiftlang/swift-syntax --mirror https://github.com/johnno1962/InstantSyntax

This can potentially ease swift-syntax replacement with its respective binary version.
The only caveat is that the repository of the mirrored package should contain all tags from the original repository for the SPM to resolve the overridden package.

Since then, the request from the Swift community for InstantSyntax has been to maintain all tags from the source package repository.

Thank you in advance.

@lyzkov lyzkov changed the title Allow original package patching using swift package mirroring Enable original package patching using swift package mirroring Aug 22, 2024
@johnno1962
Copy link
Owner

johnno1962 commented Aug 22, 2024

Maintaining tags for all those in the source repo isn't the only issue this repo faces. Versioning is a complex problem which Apple is much better situated to resolve given they have control of the related tooling. I'm afraid I won't be looking at this.

@lyzkov
Copy link
Author

lyzkov commented Aug 23, 2024

I don't know if all tags are necessary to recreate. Maybe major + or minor?
I’ve tried to replace the original swift-syntax with my fork of InstantSyntax using the package mirroring in the project that depends on The Composable Architecture and it seems that a wide range of versions is available to choose from.
Nonetheless, the compilation failed on switch covers known cases, but 'AccessorBlockSyntax.Accessors' may have additional unknown values.

EDIT:
I've tackled the issue of nonexhaustive switch by covering unknown cases in forked versions of TCA dependencies.

However, the main problem is Emit Swift module (arm64):

external macro implementation type 'PerceptionMacros.PerceptibleMacro' could not be found for macro 'Perceptible()'; '/Users/lyzkov/Library/Developer/Xcode/DerivedData/MyProject/Build/Products/Debug/PerceptionMacros' produced malformed response

I'm not sure because the build error message is very enigmatic. @vmanot Maybe you have some ideas?

I guess that the problem is caused by commenting out unsafe flags for weak frameworks to link.

let staticLink = ["\(clone)\(tag)/libSwiftSyntax.a"] +
    modules.map { $0.name }.flatMap({ module in
    ["-weak_framework", module] + platforms.flatMap({
        ["-F", "\(clone)\(tag)/\(module).xcframework/\($0)"] })
    })

(...)

    .target(
      name: "InstantSyntax"
//      linkerSettings: [.unsafeFlags(staticLink)]
    ),

I've did it get rid of package resolution error:

the target 'InstantSyntax' in product 'SwiftSyntaxMacros' contains unsafe build flags

which is (in my opinion) due to an overly restrictive SPM policy towards passing custom compilation flags.

@johnno1962 Have you been troubled with passing unsafe flags during InstantSyntax development?

@benedelstein
Copy link

I guess that the problem is caused by commenting out unsafe flags for weak frameworks to link.

let staticLink = ["\(clone)\(tag)/libSwiftSyntax.a"] +
    modules.map { $0.name }.flatMap({ module in
    ["-weak_framework", module] + platforms.flatMap({
        ["-F", "\(clone)\(tag)/\(module).xcframework/\($0)"] })
    })

(...)

    .target(
      name: "InstantSyntax"
//      linkerSettings: [.unsafeFlags(staticLink)]
    ),

I've did it get rid of package resolution error:

the target 'InstantSyntax' in product 'SwiftSyntaxMacros' contains unsafe build flags

which is (in my opinion) due to an overly restrictive SPM policy towards passing custom compilation flags.

@johnno1962 Have you been troubled with passing unsafe flags during InstantSyntax development?

@lyzkov were you able to resolve the unsafe build flag issue? It seems like the manual copying is meant to override this policy #3 (comment) but it doesn't work for me.

@lyzkov
Copy link
Author

lyzkov commented Nov 8, 2024

@benedelstein Nope. Manual copying has nothing to do with this issue because 3rd party packages that depend on the InstantSyntax package are meant by SPM policies to restrict all unsafe flags from packages they depend on.

If I remember correctly, only top-level 1st party packages can have unsafe flags specified. You would have to fork all dependencies to overwrite all unsafe flags, which is an unacceptable workaround with terrible maintenance tradeoffs.

I'd suggest waiting until the SPM guys resolve the swift-syntax prebuilt package distribution. Anyway, I hope they are not about to hack SPM's preexisting limitations through compiler flags.

@johnno1962
Copy link
Owner

I've updated he README to say this package no longer works. I've not seen it work with Xcode 16. I may archive the repo.

@johnno1962
Copy link
Owner

Seems Apple is working on a solution https://forums.swift.org/t/compilation-extremely-slow-since-macros-adoption/67921/124

@vmanot
Copy link
Collaborator

vmanot commented Dec 5, 2024

@johnno1962 @lyzkov we have a solution at @PreternaturalAI. See swift-precompiled/swift-syntax.

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

No branches or pull requests

4 participants