I've been trying to figure out how to use Swift and Metal without Xcode. I cannot figure out SwiftPM. I've tried everything I can think of, and am just going round in circles.
This is my (current) manifest (I've tried many variations):
I looked through the .build directory, and couldn't find any intermediate (Metal IR) files, so I'm sure that SwiftPM is unhappy with the manifest (it's not an error in the source files). I also copied the code from another project (that compiled fine in Xcode), which increases my confidence that this is an issue with my manifest.
If I understand correctly, the .process function either takes a filename (and processes the file) or a directory (and processes everything in the directory). Here, process means compile/optimize/etc (whatever's appropriate for a known file-type). So, running .process on a directory of Metal files should compile them all.
I've tried changing the paths (so they're incorrect), and get the expected errors, with the expected (incorrect) paths. When I correct the paths, I get the error message from above.
If you're ok with using a third party tool, my tool Swift Bundler sits on top of SwiftPM with the goal of enabling Xcodeproj-less app development. It bundles up your app's resources, dynamic libraries and main executable into a distributable .app, compiles any Metal shaders that it finds in the process, and supports macOS, iOS, tvOS and visionOS.
Swift Bundler also supports Linux now and can bundle SwiftPM executable projects into .rpm installers and .AppImage files, although Metal shader compilation isn't supported on Linux, and you need to use a cross-platform UI framework for the app to compile on Linux in the first place of course.