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

[SR-6805] generate-xcodeproj does not honor library type: .static #4900

Closed
swift-ci opened this issue Jan 21, 2018 · 3 comments
Closed

[SR-6805] generate-xcodeproj does not honor library type: .static #4900

swift-ci opened this issue Jan 21, 2018 · 3 comments
Labels

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-6805
Radar None
Original Reporter --marc (JIRA User)
Type Bug

Attachment: Download

Environment

Xcode Version 9.2 (9C40b)
Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)
Apple Swift Package Manager - Swift 4.0.0-dev (swiftpm-13752)

Additional Detail from JIRA
Votes 4
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: eca9f978ea38aeefedb1abc9ce116c45

Issue Description:

When a library is expressly declared `type: .static` in the library's Package.swift manifest, then it seems that one should reasonably expect `swift package generate-xcodeproj` to generate an Xcode project which preserves the library as static through out the build process.

Example

The following two Swift Manager Packages (SPM) packages are both attached to this issue and also available on GitHub:

  1. Static Library Depedency: `TinkerEvalStaticLib` (https://github.com/VaporExamplesLab/TinkerEvalStaticLib) used `swift package init --type library` as the starting point.

  2. Command Line Executable: `TinkerEvalStaticCli` (https://github.com/VaporExamplesLab/TinkerEvalStaticCli) used `swift package init --type executable` as the starting point.

`TinkerEvalStaticLib` has one simple function and is expressly set to a type `.static` in Package.swift.

TinkerEvalStaticLib.swift

public class TinkerEvalStaticLib {
    public static func printSomething() -> String {
        let s = "Library says, 'Hello.'"
        print(s)
        return s
    }
} 

Package.swift

…
products: [
  .library(name: "TinkerEvalStaticLib", 
           type: .static, // expressly set to be a static library
           …

`TinkerEvalStaticCli` is also simple and has the static library `TinkerEvalStaticLib` as a dependency.

main.swift

import TinkerEvalStaticLib
let _ = TinkerEvalStaticLib.printSomething() 

Package.swift

…
name: "TinkerEvalStaticCli",
dependencies: [
  .package(
    url: "git@github.com:VaporExamplesLab/TinkerEvalStaticLib.git",
        .branch("master") ),
],
…

Observation

1. In the `TinkerEvalStaticCli` directory, `swift build` will create a standalone relocatable, statically linked executable.

prompt> ./TinkerEvalStaticCli_spm 
Library says, 'Hello.'

2. However, the Xcode project created with `swift package generate-xcodeproj` creates a dynamically linked executable that requires the separate library.

prompt> ./TinkerEvalStaticCli_xc 
dyld: Library not loaded: @rpath/TinkerEvalStaticLib.framework/Versions/A/TinkerEvalStaticLib
Referenced from: /Users/…/./TinkerEvalStaticCli_xc
Reason: image not found
Abort trap: 6
@swift-ci
Copy link
Contributor Author

Comment by Marc (JIRA)

`generate-xcodeproj` does not honor the specification for a `.library` product of `type: .static` and instead generates an Xcode project for a dynamic framework with Mach-O type Dynamic Library.

This outcome occurs in both cases:

  1. When the library is a depencency. For example, "TinkerEvalStaticCli" requires "TinkerEvalStaticLib".

  2. When the library is the only product. For example, "TinkerEvalStaticLib" itself.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
@krin-san
Copy link

#5748 removed generate-xcodeproj command. I guess this issue could be closed, but without an alternative way to generate Xcode project from Package manifest projects like https://github.com/unsignedapps/swift-create-xcframework will stop working with the next Swift release.

@neonichu
Copy link
Member

Yep, agreed, let's close it.

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

No branches or pull requests

4 participants