Xcode fails to find `.o` file for a given `.target`

Hey Folks!

I was curious about the C integration using SPM, and, following Carette Antonin blogpost on C interoperability using Raylib as an example, seems I have hit a snag... Or possibly an Xcode bug?

I can build and run the project using swift run on the root of the project, with Swift version 6.3.1.

But, when I try to do the same on Xcode 26.4.1, the build immediately errors out with the following:

Build input file cannot be found: '[...]/Build/Products/Debug/craylib.o'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it?

The issue is not only present on my own project, it is also present in the blog authors example. Their project is hosted on github and the issue is reproducible. If you clone the repo, and swift run you get a window. If instead you open the project on Xcode 26.4.1 the error above is shown.

What am I missing? I suspect there should be something else included in the Package.swift but I have no idea what.

Thanks!

Below is my project structure, Package.swift and module.modulemap.

Package.swift
Sources/
  CRaylib/
    macOS/
      librarylib.a
    module.modulemap
    raylib.h
Test/
  Test.swift
// swift-tools-version: 6.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "Test",
    targets: [
        .target(
            name: "craylib",
            path: "Sources/CRaylib",
            publicHeadersPath: ".",
            linkerSettings: [
                // macOS
                .unsafeFlags(
                    ["-L", "Sources/CRaylib/macOS"],
                    .when(platforms: [.macOS])
                ),
                .linkedFramework("OpenGL", .when(platforms: [.macOS])),
                .linkedFramework("Cocoa", .when(platforms: [.macOS])),
                .linkedFramework("IOKit", .when(platforms: [.macOS])),
                .linkedFramework("CoreVideo", .when(platforms: [.macOS])),
            ],
        ),
        .executableTarget(
            name: "Test",
            dependencies: ["craylib"],
        ),
    ]
)

module CRaylib {
    header "raylib.h"
    link "raylib"
    export *
}

Xcode's build never produces an object file since there are no sources to compile (just module maps and static libraries) under Sources/CRaylib. Swift Build will use the module map and static library directly.

For Xcode to create an object file, just add an empty .c file under Sources/CRaylib and it will build on both :)

1 Like

Amazing. Empty .c file does the trick!
Thank you for the explanation! :slightly_smiling_face: