How do you print output from Package.swift execution?

Any attempt to print output from within Package.swift get's swallowed up. How can we output messages?

Thanks, Ed

You mean like a print() statement? It isn’t designed for that sort of thing, because once the package is a dependency, it might be loaded multiple times for different versions while the dependency graph is being resolved—even multiple times at once.

If you are trying to debug something, swift package has subcommands like describe, dump‐package and show-dependencies. swift package --help will show you the complete list of available commands.

No guarantees, but have you tried printing to stderr? Stdout is iirc where the manifest outputs the serialized manifest contents for SwiftPM to parse, but they might not be touching stderr :thinking:

Oh if it's loaded and executed possibly multi times then what I was thinking of doing will not work. I need to compile some Cuda kernels, so I was thinking of invoking the nvcc compiler through a task. Is there anyway to get the SwiftPM to build a static library of .cu files to link in?

I think you’ll have to wait for extensible build tools. Unless you can precompile them and rig it to work using the binary dependencies feature, which will become available sooner. Until then you’ll have to provide them separately and tell clients which extra flags to add to their command line invocation (-Xlinker, etc.).

With respect to your original idea, even if you made it check whether it had already started, so as to prevent multiple runs, you would still be facing lots of other hurdles. SwiftPM sandboxes the manifest on some platforms. It checks out the manifest in isolation without the rest of the source until it knows which commit it actually needs. It caches the loaded manifest. A dirty Git state interferes with a lot of Git operations and could cause SwiftPM to either wipe the whole thing and start over or else just crash. Git‐ignored files could be left behind when switching versions, resulting in mismatched generated files. And the list goes on...

2 Likes

One thing you can do is use NSLog. NSLog messages show up as warnings in Xcode, and also appear in Console.app

Terms of Service

Privacy Policy

Cookie Policy