Some necro here, because I managed to do it without having to disable sandboxing on modern macOS versions. The use case is very basic, and I struggle to understand why it's got to be so hard to do, but anyways.
So I have a .metallib
(Metal shader libraries) to include in my project, and it comes in Debug and Release forms, and I am loading the library from the bundle, so I need to copy the right one in the bundle depending on the configuration.
So what I did is add a Run Script
build step BEFORE the Copy Bundle Resources
step. The command:
cp $MYLIBRARY_DIRECTORY/bin/lib/ios/$CONFIGURATION/MyShaders.metallib $BUILD_DIR/
Note that $MYLIBRARY_DIRECTORY
is a location (Xcode -> Preferences -> Locations -> Custom Paths).
For proper dependency resolution, you can add that in the Input File: $(MYLIBRARY_DIRECTORY)/bin/lib/ios/$(CONFIGURATION)/MyShaders.metallib
(parentheses this time, but should not be in the build script).
And this in the output:
$(BUILD_DIR)/MyShaders.metallib
Now you need to build once and find where that file was copied, from the build log. It will look like:
/Users/<your user name>/Library/Developer/Xcode/DerivedData/<project name>-abunchofweirdcharacters/Build/Products/MyShaders.metallib
Locate it from the Finder (Cmd+Shift+G -> paste the path -> Enter). Drag and drop the file into your project. Select it and reveal the inspector on the right. From the Location
drop down, select Relative to Build Products
. The line below should now read `../MyShaders.metallib.
Now, you can open the Copy Bundle Resources
step from the Project configuration -> Build Phases
page. Click on the +
button and add the file that you just added on the project (MyShaders.metallib
). Launch a build, and it should work.