Automatically build dylib on macOS - #22147
Conversation
|
You can test this PR using the following package version. |
| <Target Name="CompileAvaloniaNativeXcodeProject" | ||
| Condition="'$(BuildAvaloniaNativeXcodeProject)' == 'true'" | ||
| BeforeTargets="DispatchToInnerBuilds;BeforeBuild" | ||
| Inputs="@(AvaloniaNativeSource)" | ||
| Outputs="$(AvaloniaNativeDylibPath)"> | ||
| <Message Importance="high" Text="Building native library $([System.IO.Path]::GetFileName($(AvaloniaNativeDylibPath)))" /> |
There was a problem hiding this comment.
We should be able to reuse the same task for CompileNative nuke target. I.e. dotnet msbuild -t:CompileAvaloniaNativeXcodeProject.
Keeping xcodeproj/CONFIGURATION_BUILD_DIR paths defined in one place (this csproj).
You might need to extract this target to be executable without BeforeTargets - shared one that can be called from the nuke.
And add a second one that depends on a shared CompileAvaloniaNativeXcodeProject and runs before BeforeBuild.
| <Target Name="CompileAvaloniaNativeXcodeProject" | ||
| Condition="'$(BuildAvaloniaNativeXcodeProject)' == 'true'" | ||
| BeforeTargets="DispatchToInnerBuilds;BeforeBuild" | ||
| Inputs="@(AvaloniaNativeSource)" |
There was a problem hiding this comment.
Please, use "inputs cache file" approach (see
Avalonia/packages/Avalonia/AvaloniaBuildTasks.targets
Lines 86 to 105 in b709c58
| <BuildAvaloniaNativeXcodeProject Condition="'$(BuildAvaloniaNativeXcodeProject)' == ''">$([MSBuild]::IsOSPlatform(OSX))</BuildAvaloniaNativeXcodeProject> | ||
| <AvaloniaNativeSourceDir>$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)../../native/Avalonia.Native))</AvaloniaNativeSourceDir> | ||
| <AvaloniaNativeXcodeProject>$(AvaloniaNativeSourceDir)/src/OSX/Avalonia.Native.OSX.xcodeproj</AvaloniaNativeXcodeProject> | ||
| <AvaloniaNativeBuildDir>$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)../../Build/Products/$(Configuration)))</AvaloniaNativeBuildDir> |
There was a problem hiding this comment.
this seems to be pointing to /build which contains our .targets/.props, am I reading this right?
| Outputs="$(AvaloniaNativeDylibPath)"> | ||
| <Message Importance="high" Text="Building native library $([System.IO.Path]::GetFileName($(AvaloniaNativeDylibPath)))" /> | ||
| <!-- TODO: Don't ignore xcode warnings, fix them instead --> | ||
| <Exec Command="xcodebuild -quiet -project "$(AvaloniaNativeXcodeProject)" -configuration $(Configuration) CONFIGURATION_BUILD_DIR="$(AvaloniaNativeBuildDir)" GCC_WARN_INHIBIT_ALL_WARNINGS=YES ONLY_ACTIVE_ARCH=NO" |
There was a problem hiding this comment.
This doesn't re-generate native headers. Nuke target does.
|
|
||
| <!-- On macOS, build the underlying Xcode project whenever one of its sources changed --> | ||
| <ItemGroup Condition="'$(BuildAvaloniaNativeXcodeProject)' == 'true'"> | ||
| <AvaloniaNativeSource Include="$(AvaloniaNativeSourceDir)/**/*.mm;$(AvaloniaNativeSourceDir)/**/*.h" /> |
There was a problem hiding this comment.
Conciser blanket $(AvaloniaNativeSourceDir)/**/* excluding avn.h (if it's built by the same target). Otherwise us adding .cpp file or someting else will break it.
What does the pull request do?
This PR automatically builds the native
dylibon macOS wheneverAvalonia.Nativeis built.Previously, one needed to manually rebuild the native library using
./build.sh CompileNative, or build it in Xcode, then build theAvalonia.NativeC# project to copy the new library.Now, a modification in a
.mmor.hfile will automatically trigger a rebuild, allowing one to just press F5 in their IDE as usual, speeding up local iteration. Build errors are reported automatically by MSBuild. Warnings are ignored for now.This PR also changes the native library to be built with the current configuration (
Debug/Release) instead of forcingRelease.