@@ -552,6 +552,73 @@ async Task DownloadWafVersion(string libddwafVersion = null, string uncompressFo
552552 }
553553 } ) ;
554554
555+ Target DownloadLibDatadog => _ => _
556+ . Unlisted ( )
557+ . After ( CreateRequiredDirectories )
558+ . Executes ( async ( ) =>
559+ {
560+ if ( IsLinux || IsOsx )
561+ {
562+ if ( ! Directory . Exists ( NativeBuildDirectory ) )
563+ {
564+ CMake . Value (
565+ arguments : $ "-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -B { NativeBuildDirectory } -S { RootDirectory } ") ;
566+ }
567+ // In CI, the folder might already exist. Which means that CMake was already configured
568+ // and libdatadog artifact (correct one) was already downloaded.
569+ // So just reuse it.
570+
571+ }
572+ else if ( IsWin )
573+ {
574+ var vcpkgExePath = await GetVcpkg ( ) ;
575+ var vcpkgRoot = Environment . GetEnvironmentVariable ( "VCPKG_ROOT" ) ?? Directory . GetParent ( vcpkgExePath ) . FullName ;
576+ var vcpkg = ToolResolver . GetLocalTool ( vcpkgExePath ) ;
577+ foreach ( var arch in new [ ] { MSBuildTargetPlatform . x64 , MSBuildTargetPlatform . x86 } )
578+ {
579+ // This big line is the same generated by VS when installing libdatadog while building the profiler
580+ vcpkg ( $ "install --x-wait-for-lock --triplet \" { arch } -windows\" --vcpkg-root \" { vcpkgRoot } \" \" --x-manifest-root={ RootDirectory } \" \" --x-install-root={ BuildArtifactsDirectory } \\ deps\\ vcpkg\\ { arch } -windows\" --downloads-root { BuildArtifactsDirectory } \\ obj\\ vcpkg\\ downloads --x-packages-root { BuildArtifactsDirectory } \\ obj\\ vcpkg\\ packages --x-buildtrees-root { BuildArtifactsDirectory } \\ obj\\ vcpkg/buildtrees --clean-after-build") ;
581+ }
582+ }
583+ } ) ;
584+
585+ Target CopyLibDatadog => _ => _
586+ . Unlisted ( )
587+ . After ( DownloadLibDatadog )
588+ . Executes ( ( ) =>
589+ {
590+ if ( IsWin )
591+ {
592+ var vcpkgDepsFolder = BuildArtifactsDirectory / "deps" / "vcpkg" ;
593+ foreach ( var architecture in new [ ] { MSBuildTargetPlatform . x64 , MSBuildTargetPlatform . x86 } )
594+ {
595+ var source = vcpkgDepsFolder / $ "{ architecture } -windows" / $ "{ architecture } -windows";
596+ if ( BuildConfiguration == Configuration . Debug )
597+ {
598+ source /= "debug" ;
599+ }
600+
601+ var dllFile = source / "bin" / "datadog_profiling_ffi.dll" ;
602+ var dest = MonitoringHomeDirectory / $ "win-{ architecture } ";
603+ CopyFileToDirectory ( dllFile , dest , FileExistsPolicy . Overwrite ) ;
604+
605+ var pdbFile = source / "bin" / "datadog_profiling_ffi.pdb" ;
606+ dest = SymbolsDirectory / $ "win-{ architecture } ";
607+ CopyFileToDirectory ( pdbFile , dest , FileExistsPolicy . Overwrite ) ;
608+ }
609+ }
610+ else if ( IsLinux || IsOsx )
611+ {
612+ var ( destArch , ext ) = GetUnixArchitectureAndExtension ( ) ;
613+
614+ var libdatadogFileName = $ "libdatadog_profiling.{ ext } ";
615+
616+ var source = NativeBuildDirectory / "libdatadog-install" / "lib" / libdatadogFileName ;
617+ var dest = MonitoringHomeDirectory / destArch ;
618+ CopyFileToDirectory ( source , dest , FileExistsPolicy . Overwrite ) ;
619+ }
620+ } ) ;
621+
555622 Target CopyNativeFilesForAppSecUnitTests => _ => _
556623 . Unlisted ( )
557624 . After ( Clean )
@@ -2746,4 +2813,71 @@ private void DotnetBuild(
27462813 . SetProcessArgumentConfigurator ( arg => arg . Add ( "/nowarn:NU1701" ) ) //nowarn:NU1701 - Package 'x' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.1'.
27472814 . CombineWith ( projPaths , ( settings , projPath ) => settings . SetProjectFile ( projPath ) ) ) ;
27482815 }
2816+
2817+
2818+ private async Task < string > GetVcpkg ( )
2819+ {
2820+ var vcpkgFilePath = string . Empty ;
2821+
2822+ try
2823+ {
2824+ vcpkgFilePath = ToolPathResolver . GetPathExecutable ( "vcpkg.exe" ) ;
2825+ }
2826+ catch ( ArgumentException )
2827+ { }
2828+
2829+ if ( File . Exists ( vcpkgFilePath ) )
2830+ {
2831+ return vcpkgFilePath ;
2832+ }
2833+
2834+ // Check if already downloaded
2835+ var vcpkgRoot = RootDirectory / "artifacts" / "bin" / "vcpkg" ;
2836+ var vcpkgExecPath = vcpkgRoot / "vcpkg.exe" ;
2837+
2838+ if ( File . Exists ( vcpkgExecPath ) )
2839+ {
2840+ return $ "{ vcpkgExecPath } ";
2841+ }
2842+
2843+ await DownloadAndExtractVcpkg ( vcpkgRoot ) ;
2844+ Cmd . Value ( arguments : $ "cmd /c { vcpkgRoot / "bootstrap-vcpkg.bat" } ") ;
2845+ return $ "{ vcpkgRoot / "vcpkg.exe" } ";
2846+ }
2847+
2848+ private async Task DownloadAndExtractVcpkg ( AbsolutePath destinationFolder )
2849+ {
2850+ var nbTries = 0 ;
2851+ var keepTrying = true ;
2852+ var vcpkgZip = TempDirectory / "vcpkg.zip" ;
2853+ using var client = new HttpClient ( ) ;
2854+ const string vcpkgVersion = "2024.11.16" ;
2855+ while ( keepTrying )
2856+ {
2857+ nbTries ++ ;
2858+ try
2859+ {
2860+ var response = await client . GetAsync ( $ "https://github.com/microsoft/vcpkg/archive/refs/tags/{ vcpkgVersion } .zip") ;
2861+ response . EnsureSuccessStatusCode ( ) ;
2862+ await using var stream = await response . Content . ReadAsStreamAsync ( ) ;
2863+ await using var file = File . Create ( vcpkgZip ) ;
2864+ await stream . CopyToAsync ( file ) ;
2865+ keepTrying = false ;
2866+ }
2867+ catch ( HttpRequestException )
2868+ {
2869+ if ( nbTries > 3 )
2870+ {
2871+ throw ;
2872+ }
2873+ }
2874+ }
2875+
2876+ EnsureExistingParentDirectory ( destinationFolder ) ;
2877+ var parentFolder = destinationFolder . Parent ;
2878+
2879+ CompressionTasks . UncompressZip ( vcpkgZip , parentFolder ) ;
2880+
2881+ RenameDirectory ( parentFolder / $ "vcpkg-{ vcpkgVersion } ", destinationFolder . Name ) ;
2882+ }
27492883}
0 commit comments