apple / swift-cmake-examples

Apache License 2.0
99 stars 9 forks source link

CXX-Interop: Fix missing header deps edge #9

Closed etcwilde closed 2 months ago

etcwilde commented 2 months ago

The custom target dependency was an order-only dependency edge. As a result, changing the swift file wouldn't result in the header getting regenerated at the right time because nothing actually depended on it being up-to-date. This patch should fix that and ties it into the fibonacci target a little more cleanly. The generated header is marked as being one of the target sources, so the target itself depends on the header getting built. This ensures that the C++ file gets rebuilt if the header changes. The header still depends on the Swift sources in the target. We're now extracting that list directly from the target itself instead of needing to pass it in explicitly. The module is also extracted from the target itself. We're also automatically adding the location of the header include directory so that dependees can find it as part of the target interface.

Fixes #8

etcwilde commented 2 months ago

@afabri, I think this should fix the issue. I've tied the header generation into the target itself a little more tightly and am now seeing the header recognized as one of the dependencies in the generated dependency file from clang.

I'm also seeing that modifying the Swift file marks the header as dirty, which then cascades to the C++ file and onward resulting in a full rebuild as expected.

ninja explain: restat of output lib/fibonacci/include/fibonacci/fibonacci-swift.h older than most recent input /Users/ewilde/Work/swift-cmake-examples/3_bidirectional_cxx_interop/lib/fibonacci/fibonacci.swift (1713650908121029567 vs 1713650920687477075)
ninja explain: /Users/ewilde/Work/swift-cmake-examples/3_bidirectional_cxx_interop/build/lib/fibonacci/include/fibonacci/fibonacci-swift.h is dirty
ninja explain: lib/fibonacci/CMakeFiles/fibonacci.dir/fibonacci.cpp.o is dirty
ninja explain: lib/fibonacci/libfibonacci.a is dirty
...