Skip to content

Commit d53571b

Browse files
CopilotMichaConrad
andcommitted
Fix native build skip: inline Condition in Target; add CleanNativeWrappers
Co-authored-by: MichaCo <5837539+MichaCo@users.noreply.github.com>
1 parent 84eac58 commit d53571b

1 file changed

Lines changed: 36 additions & 13 deletions

File tree

benchmark/CDT.Comparison.Benchmarks/CDT.Comparison.Benchmarks.csproj

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,17 @@
6666
<_NativeLibExt Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))">.dylib</_NativeLibExt>
6767
<_NativeLibExt Condition="'$(_NativeLibExt)' == ''">.so</_NativeLibExt>
6868

69+
<!-- Source-side paths (in native/*/build or target/) -->
6970
<_CdtLibFile>$(_CdtBuildDir)/$(_NativeLibPrefix)cdt_wrapper$(_NativeLibExt)</_CdtLibFile>
7071
<_CgalLibFile>$(_CgalBuildDir)/$(_NativeLibPrefix)cgal_wrapper$(_NativeLibExt)</_CgalLibFile>
7172
<_SpadeLibFile>$(_SpadeReleaseDir)/$(_NativeLibPrefix)spade_wrapper$(_NativeLibExt)</_SpadeLibFile>
7273
</PropertyGroup>
7374

7475
<!-- ── artem-ogre/CDT C++ wrapper ──────────────────────────────────────── -->
7576

76-
<!-- Friendly error when cmake is not on PATH (shared by all C++ wrappers) -->
77+
<!-- Friendly error when cmake is not on PATH (shared by both C++ wrappers).
78+
BeforeTargets means this is also skipped when its owning targets are
79+
skipped via Condition (i.e. when the output libs already exist). -->
7780
<Target Name="CheckCmake" BeforeTargets="BuildCdtNative;BuildCgalNative">
7881
<Exec Command="cmake --version"
7982
IgnoreExitCode="true"
@@ -86,26 +89,37 @@
8689
Text="cmake was not found on PATH. It is required to build the C++ wrappers. Install CMake from https://cmake.org/download/ and ensure it is on your PATH." />
8790
</Target>
8891

89-
<Target Name="BuildCdtNative" BeforeTargets="Build" DependsOnTargets="CheckCmake">
92+
<!--
93+
IMPORTANT: $(OutputPath) is empty at PropertyGroup evaluation time in SDK-style
94+
projects, so the output lib paths must be inlined directly in Condition attributes
95+
(which are evaluated at target-execution time when $(OutputPath) is fully resolved).
96+
97+
Condition="!Exists('$(OutputPath)...')" means:
98+
• First build (or after `dotnet clean`): output lib is missing → run cmake/cargo.
99+
The BeforeTargets check targets (CheckCmake/CheckCargo) also run.
100+
• Every subsequent `dotnet build`: output lib already in output dir → entire
101+
target AND its BeforeTargets prerequisites are skipped — no cmake or cargo invoked.
102+
The cmake/cargo build dirs (native/*/build, native/*/target) are NOT cleaned by
103+
`dotnet clean`, so a rebuild after clean is fast (only re-links if needed).
104+
-->
105+
<Target Name="BuildCdtNative" BeforeTargets="Build"
106+
Condition="!Exists('$(OutputPath)$(_NativeLibPrefix)cdt_wrapper$(_NativeLibExt)')">
90107
<MakeDir Directories="$(_CdtBuildDir)" />
91108
<Exec Command="cmake -S &quot;$(_CdtNativeDir)&quot; -B &quot;$(_CdtBuildDir)&quot; -DCMAKE_BUILD_TYPE=Release" />
92109
<Exec Command="cmake --build &quot;$(_CdtBuildDir)&quot; --config Release" />
93110
<MakeDir Directories="$(OutputPath)" />
94-
<Copy SourceFiles="$(_CdtLibFile)"
95-
DestinationFolder="$(OutputPath)"
96-
SkipUnchangedFiles="true" />
111+
<Copy SourceFiles="$(_CdtLibFile)" DestinationFolder="$(OutputPath)" SkipUnchangedFiles="true" />
97112
</Target>
98113

99114
<!-- ── CGAL C++ wrapper ─────────────────────────────────────────────────── -->
100115

101-
<Target Name="BuildCgalNative" BeforeTargets="Build" DependsOnTargets="CheckCmake">
116+
<Target Name="BuildCgalNative" BeforeTargets="Build"
117+
Condition="!Exists('$(OutputPath)$(_NativeLibPrefix)cgal_wrapper$(_NativeLibExt)')">
102118
<MakeDir Directories="$(_CgalBuildDir)" />
103119
<Exec Command="cmake -S &quot;$(_CgalNativeDir)&quot; -B &quot;$(_CgalBuildDir)&quot; -DCMAKE_BUILD_TYPE=Release" />
104120
<Exec Command="cmake --build &quot;$(_CgalBuildDir)&quot; --config Release" />
105121
<MakeDir Directories="$(OutputPath)" />
106-
<Copy SourceFiles="$(_CgalLibFile)"
107-
DestinationFolder="$(OutputPath)"
108-
SkipUnchangedFiles="true" />
122+
<Copy SourceFiles="$(_CgalLibFile)" DestinationFolder="$(OutputPath)" SkipUnchangedFiles="true" />
109123
</Target>
110124

111125
<!-- ── Spade Rust wrapper ───────────────────────────────────────────────── -->
@@ -123,12 +137,21 @@
123137
Text="cargo was not found on PATH. It is required to build the Spade Rust wrapper. Install Rust from https://rustup.rs/ and ensure cargo is on your PATH." />
124138
</Target>
125139

126-
<Target Name="BuildSpadeNative" BeforeTargets="Build" DependsOnTargets="CheckCargo">
140+
<Target Name="BuildSpadeNative" BeforeTargets="Build"
141+
Condition="!Exists('$(OutputPath)$(_NativeLibPrefix)spade_wrapper$(_NativeLibExt)')">
127142
<Exec Command="cargo build --release --manifest-path &quot;$(_SpadeNativeDir)/Cargo.toml&quot;" />
128143
<MakeDir Directories="$(OutputPath)" />
129-
<Copy SourceFiles="$(_SpadeLibFile)"
130-
DestinationFolder="$(OutputPath)"
131-
SkipUnchangedFiles="true" />
144+
<Copy SourceFiles="$(_SpadeLibFile)" DestinationFolder="$(OutputPath)" SkipUnchangedFiles="true" />
145+
</Target>
146+
147+
<!-- ── Clean hook ───────────────────────────────────────────────────────── -->
148+
149+
<!-- Remove the native libs from the output dir when `dotnet clean` runs,
150+
so the next build will re-copy (and re-compile if needed) them. -->
151+
<Target Name="CleanNativeWrappers" AfterTargets="Clean">
152+
<Delete Files="$(OutputPath)$(_NativeLibPrefix)cdt_wrapper$(_NativeLibExt);
153+
$(OutputPath)$(_NativeLibPrefix)cgal_wrapper$(_NativeLibExt);
154+
$(OutputPath)$(_NativeLibPrefix)spade_wrapper$(_NativeLibExt)" />
132155
</Target>
133156

134157
</Project>

0 commit comments

Comments
 (0)