Skip to content

Commit 694bc60

Browse files
authored
Improve native build and mark our official build as CFS Clean (#7516)
* Pass additional settings when compiling native binaries * Mark our build as CFSClean
1 parent bd61ee8 commit 694bc60

File tree

5 files changed

+47
-16
lines changed

5 files changed

+47
-16
lines changed

build/vsts-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ extends:
5656
enabled: true
5757
tsa:
5858
enabled: true
59+
settings:
60+
networkIsolationPolicy: Permissive,CFSClean
5961
pool:
6062
name: $(DncEngInternalBuildPool)
6163
image: $(WindowsImage)

src/Native/CMakeLists.txt

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ set(RESOURCES)
1313
# Include 'bin/obj' dir since it contains _version.h
1414
include_directories("$ENV{__IntermediatesDir}")
1515

16+
# Define path to native source link file
17+
set(NATIVE_SOURCELINK_FILE_PATH "$ENV{__IntermediatesDir}/native.sourcelink.json")
18+
1619
if(WIN32)
1720
add_definitions(-DWIN32)
1821
add_definitions(-D_WIN32=1)
@@ -22,11 +25,9 @@ if(WIN32)
2225
endif()
2326
add_compile_options($<$<CONFIG:Debug>:-DDEBUG>)
2427
add_compile_options($<$<CONFIG:Release>:-DNDEBUG>)
25-
add_compile_options($<$<CONFIG:RelWithDebInfo>:-DNDEBUG>)
2628
add_compile_options($<$<CONFIG:Debug>:/Od>)
2729
add_compile_options($<$<CONFIG:Debug>:/MTd>) # /MT will static link the VC runtime library, so it doesn't need to be installed on the target machine
2830
add_compile_options($<$<CONFIG:Release>:/MT>)
29-
add_compile_options($<$<CONFIG:RelWithDebInfo>:/MT>)
3031
add_compile_options(/guard:cf)
3132
add_compile_options(/Zo) # make optimized builds debugging easier. /Zo is the newer documented flag.
3233
add_compile_options(/nologo) # Suppress Startup Banner
@@ -41,6 +42,11 @@ if(WIN32)
4142
add_compile_options(/Zc:inline)
4243
add_compile_options(/fp:precise)
4344
add_compile_options(/EHsc)
45+
add_compile_options(/Brepro)
46+
add_compile_options(/d1nodatetime)
47+
add_compile_options(/experimental:deterministic)
48+
add_compile_options(/GL)
49+
add_compile_options(/d2CastGuardFailureMode:fastfail)
4450

4551
# From here below are warnings required to be explicitly enabled.
4652
add_compile_options(/w34242)
@@ -62,27 +68,27 @@ if(WIN32)
6268
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG /PDBCOMPRESS")
6369
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:1572864")
6470

65-
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /guard:cf")
66-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf")
71+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /guard:cf /Brepro")
72+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf /Brepro")
73+
74+
# Enable native source link if the source link file exists
75+
if(EXISTS ${NATIVE_SOURCELINK_FILE_PATH})
76+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /sourcelink:${NATIVE_SOURCELINK_FILE_PATH}")
77+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /sourcelink:${NATIVE_SOURCELINK_FILE_PATH}")
78+
endif(EXISTS ${NATIVE_SOURCELINK_FILE_PATH})
6779

6880
# Debug build specific flags
6981
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "/NOVCFEATURE")
7082
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:vcompd.lib /DEFAULTLIB:vcomp.lib")
7183
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:vcompd.lib /DEFAULTLIB:vcomp.lib")
7284

7385
# Release build specific flags
74-
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
75-
set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
76-
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
86+
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF /LTCG")
87+
set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF /LTCG")
88+
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF /LTCG")
7789
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
7890
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
7991

80-
# RelWithDebInfo specific flags
81-
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /DEBUG /OPT:REF /OPT:ICF")
82-
set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO} /DEBUG /OPT:REF /OPT:ICF")
83-
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /DEBUG /OPT:REF /OPT:ICF")
84-
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
85-
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
8692
list(APPEND RESOURCES $ENV{__IntermediatesDir}/NativeVersion.rc)
8793
else()
8894
add_compile_options(-Wno-unused-local-typedef)

src/Native/Native.proj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
4949
<GenerateNativeVersionInfo>true</GenerateNativeVersionInfo>
5050
<NativeVersionFile>$(IntermediateOutputPath)_version.h</NativeVersionFile>
51+
<NativeSourceLinkFile>$(IntermediateOutputPath)native.sourcelink.json</NativeSourceLinkFile>
5152
</PropertyGroup>
5253

5354
<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
@@ -120,7 +121,7 @@
120121

121122
<Target Name="BuildNativeWindows"
122123
Condition="'$(OS)' == 'Windows_NT'"
123-
DependsOnTargets="GenerateNativeVersionFile">
124+
DependsOnTargets="GenerateNativeVersionFile;GenerateNativeSourcelinkFile">
124125

125126
<PropertyGroup>
126127
<BuildArgs>$(Configuration) $(TargetArchitecture) --mkllibpath $(NuGetPackageRoot)mlnetmkldeps\$(MlNetMklDepsVersion)\runtimes\$(PackageRid)\native</BuildArgs>
@@ -248,6 +249,15 @@
248249

249250
</Target>
250251

252+
<Target Name="GenerateNativeSourcelinkFile"
253+
DependsOnTargets="GenerateSourceLinkFile"
254+
Condition="'$(DisableSourceLink)' != 'true' and '$(OS)' == 'Windows_NT'"
255+
Inputs="$(SourceLink)"
256+
Outputs="$(NativeSourceLinkFile)">
257+
<Error Condition="'$(SourceLink)' == ''" Text="Please set SourceLink to forward appropriate information for sourcelink."/>
258+
<Copy SourceFiles="$(SourceLink)" DestinationFiles="$(NativeSourceLinkFile)" />
259+
</Target>
260+
251261
<Target Name="Pack" />
252262
<Target Name="Test" />
253263

src/Native/build.cmd

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ setlocal
33

44
:: Store current script directory before %~dp0 gets affected by another process later.
55
set __currentScriptDir=%~dp0
6+
set "__currentScriptDir=%__currentScriptDir:~0,-1%"
7+
68

79
:SetupArgs
810
:: Initialize the args that will be passed to cmake
9-
set __rootDir=%__currentScriptDir%..\..
11+
set __rootDir=%__currentScriptDir%\..\..
1012
set __artifactsDir=%__rootDir%\artifacts
1113
set __binDir=%__artifactsDir%\bin
1214
set __objDir=%__artifactsDir%\obj
@@ -51,7 +53,9 @@ set "VSCMD_START_DIR=%__currentScriptDir%"
5153
call "%_VSCOMNTOOLS%\VsDevCmd.bat"
5254

5355
:RunVCVars
54-
if "%VisualStudioVersion%"=="17.0" (
56+
if "%VisualStudioVersion%"=="18.0" (
57+
goto :VS2026
58+
) else if "%VisualStudioVersion%"=="17.0" (
5559
goto :VS2022
5660
) else if "%VisualStudioVersion%"=="16.0" (
5761
goto :VS2019
@@ -67,6 +71,14 @@ echo Error: Visual Studio 2015, 2017, 2019, or 2022 required
6771
echo Please see https://github.com/dotnet/machinelearning/tree/main/Documentation for build instructions.
6872
exit /b 1
6973

74+
:VS2026
75+
:: Setup vars for VS2026
76+
set __PlatformToolset=v145
77+
set __VSVersion=18 2026
78+
:: Set the environment for the native build
79+
call "%VS180COMNTOOLS%..\..\VC\Auxiliary\Build\vcvarsall.bat" %__VCBuildArch%
80+
goto :SetupDirs
81+
7082
:VS2022
7183
:: Setup vars for VS2022
7284
set __PlatformToolset=v143

src/Native/gen-buildsys-win.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ if /i "%3" == "x64" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A x64)
3030
if /i "%3" == "x86" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A Win32)
3131
if /i "%3" == "arm64" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A arm64)
3232
if /i "%3" == "arm" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A arm)
33+
echo "%CMakePath%" "-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%" "-DCMAKE_INSTALL_PREFIX=%__CMakeBinDir%" "-DMKL_LIB_PATH=%MKL_LIB_PATH%" "-DONEDAL_DEVEL_PATH=%ONEDAL_DEVEL_PATH%" "-DONETBB_DEVEL_PATH=%ONETBB_DEVEL_PATH%" "-DARCHITECTURE=%3" -G "Visual Studio %__VSString%" %__ExtraCmakeParams% -B. -H%1
3334
"%CMakePath%" "-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%" "-DCMAKE_INSTALL_PREFIX=%__CMakeBinDir%" "-DMKL_LIB_PATH=%MKL_LIB_PATH%" "-DONEDAL_DEVEL_PATH=%ONEDAL_DEVEL_PATH%" "-DONETBB_DEVEL_PATH=%ONETBB_DEVEL_PATH%" "-DARCHITECTURE=%3" -G "Visual Studio %__VSString%" %__ExtraCmakeParams% -B. -H%1
3435
endlocal
3536
GOTO :DONE

0 commit comments

Comments
 (0)