Skip to content

Instantly share code, notes, and snippets.

@tonisuter tonisuter/main.swift
Last active Jul 10, 2017

What would you like to do?
Testing libSwiftPM
import Basic
import PackageGraph
import PackageLoading
import Workspace
class MyWorkspaceDelegate: WorkspaceDelegate {
func packageGraphWillLoad(currentGraph: PackageGraph, dependencies: AnySequence<ManagedDependency>, missingURLs: Set<String>) {
func fetching(repository: String) {
print("fetching \(repository)")
func cloning(repository: String) {
print("cloning \(repository)")
func checkingOut(repository: String, at reference: String) {
print("checking out \(repository)")
func removing(repository: String) {
print("removing \(repository)")
func warning(message: String) {
print("warning \(message)")
func managedDependenciesDidUpdate(_ dependencies: AnySequence<ManagedDependency>) {
struct MyManifestResourceProvider: ManifestResourceProvider {
var swiftCompiler = AbsolutePath("/Applications/")
var libDir = AbsolutePath("/Users/tonisuter/Projects/swift-package-manager/.build/lib/swift/pm")
func printManifest(pkgPath: AbsolutePath) {
let manifestLoader = ManifestLoader(resources: MyManifestResourceProvider())
let workspace = Workspace(
dataPath: pkgPath.appending(component: ".build"),
editablesPath: pkgPath.appending(component: "Packages"),
pinsFile: pkgPath.appending(component: "Package.pins"),
manifestLoader: manifestLoader,
delegate: MyWorkspaceDelegate()
let diagnosticsEngine = DiagnosticsEngine()
let manifests = workspace.loadRootManifests(packages: [pkgPath], diagnostics: diagnosticsEngine)
if let manifest = manifests.first {
} else {
for diagnostic in diagnosticsEngine.diagnostics {
printManifest(pkgPath: AbsolutePath("/Users/tonisuter/Downloads/MyProj"))

This comment has been minimized.

Copy link
Owner Author

commented Apr 18, 2017

My file structure looks like this and additionally, there's a regular, empty SwiftPM project at the path /Users/tonisuter/Downloads/MyProj:

├── include
│   ├── Basic.swiftmodule
│   ├── Build.swiftmodule
│   ├── POSIX.swiftmodule
│   ├── PackageDescription.swiftmodule
│   ├── PackageDescription4.swiftmodule
│   ├── PackageGraph.swiftmodule
│   ├── PackageLoading.swiftmodule
│   ├── PackageModel.swiftmodule
│   ├── SourceControl.swiftmodule
│   ├── Utility.swiftmodule
│   ├── Workspace.swiftmodule
│   ├── Xcodeproj.swiftmodule
│   ├── clibc.h
│   ├── libc.swiftmodule
│   └── module.modulemap
├── lib
│   └── libSwiftPM.dylib
└── main.swift

And I am using the following command to compile and run main.swift:

xcrun swift -I ./include -L ./lib -lSwiftPM -module-link-name SwiftPM main.swift

However, when I run the command I get the following error:

manifest parse error(s):
/Users/tonisuter/Downloads/MyProj/Package.swift:3:8: error: no such module 'PackageDescription'
import PackageDescription

This comment has been minimized.

Copy link
Owner Author

commented Apr 19, 2017

The problem was that I used the libSwiftPM library from the master branch, but the libDir path was set to /Applications/ (i.e., the folder that contains the libPackageDescription.dylib of the current version of Xcode). Instead, I had to execute the following command in the Swift Package Manager repository:

<Path-To-SwiftPM-Repository>/Utilities/bootstrap --libswiftpm-library-dir "/tmp/libSwiftPM/install/dir/include" --libswiftpm-modules-dir "/tmp/libSwiftPM/install/dir/lib"

Finally, the libDir path needs to be set to <Path-To-SwiftPM-Repository>/.build/lib/swift/pm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.