Skip to content

Add missing steps to creating a C library package. #1

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 1 commit into from
Nov 20, 2015

Conversation

emish
Copy link
Contributor

@emish emish commented Nov 20, 2015

I added a couple extra steps to get this example working.

mxcl added a commit that referenced this pull request Nov 20, 2015
Add missing steps to creating a C library package.
@mxcl mxcl merged commit 4c9c73e into swiftlang:master Nov 20, 2015
@mxcl
Copy link
Contributor

mxcl commented Nov 20, 2015

I actually added this myself, but your docs are better, so I'll revert my commit.

@emish emish deleted the docUpdate branch November 20, 2015 18:03
aciidgh referenced this pull request in aciidgh/swift-package-manager Sep 18, 2017
aciidgh referenced this pull request in aciidgh/swift-package-manager Jan 11, 2019
Small typos in buildengine documentation.
DougGregor pushed a commit that referenced this pull request Aug 25, 2024
…wift identifier (#7764)

Executing `swift package add-target my-target --type executable` breaks
the updated package because the executable target name is not a valid
Swift identifier.

### Motivation:
After executing `swift package add-target my-target --type executable`,
I expect the generated stub to not break the modified package. However,
in this case, the resulting stub file would contain invalid Swift code:
```swift
@main
struct my-targetMain {
    static func main() {
        print("Hello, world")
    }
}
```
The same issue applies to `macro` and `test` target types. It's also
important to note that `dash case` is quite often used for target names,
like e.g. in
[swift-argument-parser](https://github.com/apple/swift-argument-parser/blob/main/Package.swift#L65-L68).

Additionaly, when `AddTarget` is consumed via an API (as opposed to the
CLI), the following parsing error is thrown into `stdout`:

<img width="796" alt="Screenshot 2024-07-08 at 08 40 51"
src="https://github.com/swiftlang/swift-package-manager/assets/1008612/c2696127-3e34-47a2-aa60-a843cfb64bda">

### Modifications:

I believe there are at least two ways to solve this issue:
1. Use a predefined type name in the generated stub, such as `struct
ExampleMain`, so it doesn't depend on the target name.
2. Introduce a sanitizer function to ensure that the target name is
always a valid Swift identifier. For example, a function that would
convert "$my-target-name%" into "myTargetName".

For the sake of simplicity, I opted for approach `#1` in the proposed
PR. However, if it's necessary to preserve target names in the generated
stubs, we can certainly go with approach `#2`.

### Result:

`swift package add-target my-target --type executable`
```swift
@main
struct ExampleMain {
    static func main() {
        print("Hello, world")
    }
}
```
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