Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move optdata and version file generation up to MSBuild from build-runtime #58674

Merged
merged 47 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
bff7536
Move optdata and version file generation from the native build script…
jkoritzinsky Sep 3, 2021
a8b692c
Update CI to use the new prereqs model.
jkoritzinsky Sep 3, 2021
1813a73
Remove some old MSBuild arg pass-through that's no longer needed as b…
jkoritzinsky Sep 3, 2021
81f808e
Apply suggestions from code review
jkoritzinsky Sep 8, 2021
db7eb91
Move some targets around based on feedback.
jkoritzinsky Sep 8, 2021
5fbd69e
Output version files in the artifacts/obj dir so they can be easily s…
jkoritzinsky Sep 8, 2021
790204b
Move native pgo into a targets file instead of being a separate proje…
jkoritzinsky Sep 8, 2021
751f259
Fix subsets.
jkoritzinsky Sep 8, 2021
1066209
Share version file path by default
jkoritzinsky Sep 8, 2021
2bb8b1d
Fix VER_FILEDESCRIPTION_STR
jkoritzinsky Sep 8, 2021
0d1e82b
Fix version fallback copies.
jkoritzinsky Sep 8, 2021
99fb01f
Fix include path for the version headers.
jkoritzinsky Sep 9, 2021
0411fab
Update src/coreclr/dlls/mscordac/CMakeLists.txt
jkoritzinsky Sep 9, 2021
70afaad
Enable easily sharing the fallback version files between all componen…
jkoritzinsky Sep 9, 2021
d4e8d9c
Remove some now-unused command-line options from our build scripts.
jkoritzinsky Sep 9, 2021
dd83c26
Bump importance output to pass the pgo path between steps.
jkoritzinsky Sep 9, 2021
19a327c
Add eval statement to run copy_version_files script
jkoritzinsky Sep 9, 2021
aa62517
Rename some files and and standardize on a _version.c file name for L…
jkoritzinsky Sep 9, 2021
7ddf99c
Remove temp proj ref.
jkoritzinsky Sep 9, 2021
9817bc5
Fix permissions
jkoritzinsky Sep 9, 2021
bfcff4d
Reference targets to produce version file in libraries native build.
jkoritzinsky Sep 10, 2021
7d0a041
Merge branch 'no-msbuild-in-build-runtime' of /mnt/d/source/runtime i…
jkoritzinsky Sep 10, 2021
032bf86
Fix CoreCLR build breaks
jkoritzinsky Sep 10, 2021
00333fc
Generate the version files for Mono
jkoritzinsky Sep 10, 2021
8d5745d
include configurepaths.cmake on the Windows CoreFX build.
jkoritzinsky Sep 10, 2021
cfe980a
Restore mono.proj when building it through monoaotcross.proj.
jkoritzinsky Sep 13, 2021
5fbb5bd
Update copy script to work on macos.
jkoritzinsky Sep 13, 2021
7340c8e
Make sure mono pulls in the shared version files.
jkoritzinsky Sep 13, 2021
0a3c1c5
Add artifcats/obj dir as include dir for CoreCLR diagonstic component…
jkoritzinsky Sep 13, 2021
7898e75
Add artifacts/obj include for the whole mono build.
jkoritzinsky Sep 14, 2021
c0dcc5c
Update CMakeLists.txt
jkoritzinsky Sep 15, 2021
22e1a60
Fix NativeVersion.rc path on Windows.
jkoritzinsky Sep 15, 2021
879be00
Fix linux version parsing to point at the right file.
jkoritzinsky Sep 15, 2021
d871c22
Fix mono version parsing (apparently the quotes make a difference here)
jkoritzinsky Sep 17, 2021
a9b03d6
Update src/coreclr/build-runtime.sh
jkoritzinsky Sep 20, 2021
f9aa7be
Update eng/native/version/copy_version_files.sh
jkoritzinsky Sep 21, 2021
83b726a
Update copy_version_files.sh to insert the current commit hash into _…
jkoritzinsky Sep 21, 2021
7423625
Apply suggestions from code review
jkoritzinsky Sep 21, 2021
272fb26
Update the _version.c writing script to only update the placeholder v…
jkoritzinsky Sep 22, 2021
21fe213
Generate the version files for wasm/browser as well.
jkoritzinsky Sep 23, 2021
fb4b07c
Merge branch 'main' into no-msbuild-in-build-runtime
jkoritzinsky Oct 5, 2021
44cc7af
Merge branch 'main' of https://github.com/dotnet/runtime into no-msbu…
jkoritzinsky Oct 11, 2021
52aaaf8
Fix Mono WASM cross build.
jkoritzinsky Oct 11, 2021
28d72d6
Merge branch 'main' into no-msbuild-in-build-runtime
jkoritzinsky Oct 15, 2021
fdfc57c
Update eng/nativepgo.targets
jkoritzinsky Oct 19, 2021
6cfcf9a
Merge branch 'main' into no-msbuild-in-build-runtime
jkoritzinsky Oct 26, 2021
9115b47
Fix comparison for NativeOptimizationDataSupported.
jkoritzinsky Oct 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/workflow/building/coreclr/android.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ When cross compiling, you need to set both the `CONFIG_DIR` and `ROOTFS_DIR` var
To compile for arm64, run:

```
CONFIG_DIR=`realpath cross/android/arm64` ROOTFS_DIR=`realpath cross/android-rootfs/toolchain/arm64/sysroot` ./build.sh cross arm64 skipgenerateversion skipmscorlib cmakeargs -DENABLE_LLDBPLUGIN=0
CONFIG_DIR=`realpath cross/android/arm64` ROOTFS_DIR=`realpath cross/android-rootfs/toolchain/arm64/sysroot` ./build.sh cross arm64 cmakeargs -DENABLE_LLDBPLUGIN=0
```

The resulting binaries will be found in `artifacts/bin/coreclr/Linux.BuildArch.BuildType/`
Expand Down
4 changes: 2 additions & 2 deletions docs/workflow/building/libraries/freebsd-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ index 81b8c7b..bb26868 100644
+++ b/repos/coreclr.proj
@@ -5,6 +5,7 @@
<BuildArguments>$(Platform) $(Configuration) skiptests</BuildArguments>
<BuildArguments Condition="'$(SkipDisablePgo)' != 'true'">$(BuildArguments) -nopgooptimize</BuildArguments>
<BuildArguments Condition="'$(TargetOS)' != 'windows'">$(BuildArguments) msbuildonunsupportedplatform</BuildArguments>
<BuildArguments Condition="'$(SkipDisablePgo)' != 'true'">$(BuildArguments)</BuildArguments>
<BuildArguments Condition="'$(TargetOS)' != 'windows'">$(BuildArguments)</BuildArguments>
+ <BuildArguments Condition="'$(TargetOS)' == 'FreeBSD'">$(BuildArguments) -clang6.0</BuildArguments>
<BuildArguments Condition="'$(UseSystemLibraries)' == 'true'">$(BuildArguments) cmakeargs -DCLR_CMAKE_USE_SYSTEM_LIBUNWIND=TRUE</BuildArguments>
<BuildArguments Condition="$(Platform.Contains('arm'))">$(BuildArguments) skipnuget cross -skiprestore cmakeargs -DFEATURE_GDBJIT=TRUE</BuildArguments>
Expand Down
16 changes: 7 additions & 9 deletions eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<ItemGroup>
<!-- CoreClr -->
<SubsetName Include="Clr" Description="The CoreCLR runtime, LinuxDac, CoreLib (+ native), tools and packages." />
<SubsetName Include="Clr.DacTools" Description="Managed tools that support building a runtime that supports debugging (such as DacTableGen)." />
<SubsetName Include="Clr.NativePrereqs" Description="Managed tools that support building the native components of the runtime (such as DacTableGen)." />
<SubsetName Include="Clr.ILTools" Description="The CoreCLR IL tools." />
<SubsetName Include="Clr.Runtime" Description="The CoreCLR .NET runtime." />
<SubsetName Include="Clr.Native" Description="All CoreCLR native non-test components, including the runtime, jits, and other native tools." />
Expand All @@ -120,7 +120,7 @@
<SubsetName Include="Mono.WasmRuntime" Description="The WebAssembly runtime." />
<SubsetName Include="Mono.MsCorDbi" Description="The implementation of ICorDebug interface." />
<SubsetName Include="Mono.Workloads" OnDemand="true" Description="Builds the installers and the insertion metadata for Blazor workloads." />

<!-- Libs -->
<SubsetName Include="Libs" Description="The libraries native part, refs and source assemblies, test infra and packages, but NOT the tests (use Libs.Tests to request those explicitly)" />
<SubsetName Include="Libs.Native" Description="The native libraries used in the shared framework." />
Expand Down Expand Up @@ -164,12 +164,6 @@
<ProjectToBuild Include="$(CoreClrProjectRoot)System.Private.CoreLib\System.Private.CoreLib.csproj" Category="clr" />
</ItemGroup>

<ItemGroup Condition="'$(TargetOS)' == 'windows' and ($(_subset.Contains('+clr.dactools+')) or $(_subset.Contains('+clr.runtime+')) or $(_subset.Contains('+clr.native+')))">
<ProjectToBuild Include="$(CoreClrProjectRoot)ToolBox\SOS\DacTableGen\DacTableGen.csproj;
$(CoreClrProjectRoot)ToolBox\SOS\DIALib\DIALib.ilproj"
Category="clr"/>
</ItemGroup>

<PropertyGroup Condition="$(_subset.Contains('+clr.runtime+'))">
<ClrRuntimeBuildSubsets>$(ClrRuntimeBuildSubsets);ClrRuntimeSubset=true</ClrRuntimeBuildSubsets>
</PropertyGroup>
Expand All @@ -194,6 +188,10 @@
<ClrRuntimeBuildSubsets>$(ClrRuntimeBuildSubsets);ClrILToolsSubset=true</ClrRuntimeBuildSubsets>
</PropertyGroup>

<ItemGroup Condition="'$(ClrRuntimeBuildSubsets)' != '' or $(_subset.Contains('+clr.nativeprereqs+'))">
<ProjectToBuild Include="$(CoreClrProjectRoot)runtime-prereqs.proj" Category="clr" />
</ItemGroup>

<ItemGroup Condition="'$(ClrRuntimeBuildSubsets)' != ''">
<ProjectToBuild Include="$(CoreClrProjectRoot)runtime.proj" AdditionalProperties="%(AdditionalProperties);$(ClrRuntimeBuildSubsets)" Category="clr" />
</ItemGroup>
Expand Down Expand Up @@ -259,7 +257,7 @@
<ItemGroup Condition="$(_subset.Contains('+mono.corelib+'))">
<ProjectToBuild Include="$(MonoProjectRoot)System.Private.CoreLib\System.Private.CoreLib.csproj" Category="mono" />
</ItemGroup>

<ItemGroup Condition="$(_subset.Contains('+mono.workloads+'))">
<ProjectToBuild Include="$(WorkloadsProjectRoot)\workloads.csproj" Category="mono" />
</ItemGroup>
Expand Down
80 changes: 2 additions & 78 deletions eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,6 @@ initTargetDistroRid()
initDistroRidGlobal "$__TargetOS" "$__BuildArch" "$__PortableBuild" "$passedRootfsDir"
}

isMSBuildOnNETCoreSupported()
{
__IsMSBuildOnNETCoreSupported="$__msbuildonunsupportedplatform"

if [[ "$__IsMSBuildOnNETCoreSupported" == 1 ]]; then
return
fi

if [[ "$__SkipManaged" == 1 ]]; then
__IsMSBuildOnNETCoreSupported=0
return
fi

if [[ ( "$__HostOS" == "Linux" ) && ( "$__HostArch" == "x64" || "$__HostArch" == "arm" || "$__HostArch" == "armel" || "$__HostArch" == "arm64" || "$__HostArch" == "s390x" ) ]]; then
__IsMSBuildOnNETCoreSupported=1
elif [[ ( "$__HostOS" == "OSX" || "$__HostOS" == "FreeBSD" ) && "$__HostArch" == "x64" ]]; then
__IsMSBuildOnNETCoreSupported=1
fi
}

setup_dirs()
{
echo Setting up directories for build
Expand Down Expand Up @@ -68,6 +48,8 @@ check_prereqs()

build_native()
{
eval "$__RepoRootDir/eng/native/version/copy_version_files.sh"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just inline the cp line (as done on line 52) rather than indirection and eval? Note that we don't always have 1:1 correspondence between .sh and .cmd, when it comes to internal scripts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to move towards a 1:1 correspondence to simplify maintenance costs.

Copy link
Member

@am11 am11 Sep 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate file is alright, but concern was regarding usage of eval: in other places like this file's (build-commons.sh) own usage, we have managed to avoid eval by using sourcing. eval is generally considered as a last resort in scripting languages. We can use source copy_version_files.sh (or . copy_version_files.sh) syntax here as well.

This is my ideal version of copy_version_files.sh, consistent with most of the existing code:

#!/usr/bin/env bash

# `source` this file, as we do for `build-common.sh`'s call-sites.
# i.e. __RepoRootDir etc. are already defined in caller scripts.

__VersionFolder="$__RepoRootDir/eng/native/version"

for path in "${__VersionFolder}/"*{.h,.c}; do
    if [ ! -s "$__RepoRootDir/artifacts/obj/$(basename "$path")" ]; then
        cp "$path" "$__RepoRootDir/artifacts/obj/"

        if [[ "$path" == *_version.c ]]; then
            # update commit
            commit="$(git rev-parse HEAD 2>/dev/null)"
            commit="${commit:-N/A}"
            substitute="$(printf 'static char sccsid[] __attribute__((used)) = "@(#)Version N/A @Commit: %s";\n' "$commit")"
            sed -i '' "s|^static.*|$substitute|" "$__RepoRootDir/artifacts/obj/_version.c"
        fi
    fi
done

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testing purposes, it's very nice to be able to manually call this script without having to set up any environment variables beforehand. I'd like to keep that experience if possible. If there's a way to call into another script using the current scripting engine when the path is constructed from vars in bash, I'd happily switch to that from eval.


targetOS="$1"
platformArch="$2"
cmakeDir="$3"
Expand Down Expand Up @@ -101,50 +83,7 @@ build_native()
buildTool="make"
fi

runtimeVersionHeaderFile="$intermediatesDir/../runtime_version.h"
if [[ "$__SkipConfigure" == 0 ]]; then
# if msbuild is not supported, then set __SkipGenerateVersion to 1
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
if [[ "$__IsMSBuildOnNETCoreSupported" == 0 ]]; then __SkipGenerateVersion=1; fi
# Drop version.c file
__versionSourceFile="$intermediatesDir/version.c"

if [[ ! -z "${__LogsDir}" ]]; then
__binlogArg="-bl:\"$__LogsDir/GenNativeVersion_$__TargetOS.$__BuildArch.$__BuildType.binlog\""
fi

if [[ "$__SkipGenerateVersion" == 0 ]]; then
"$__RepoRootDir/eng/common/msbuild.sh" /clp:nosummary "$__ArcadeScriptArgs" "$__RepoRootDir"/eng/empty.csproj \
/p:NativeVersionFile="$__versionSourceFile" \
/p:RuntimeVersionFile="$runtimeVersionHeaderFile" \
/t:GenerateRuntimeVersionFile /restore \
$__CommonMSBuildArgs $__binlogArg $__UnprocessedBuildArgs
local exit_code="$?"
if [[ "$exit_code" != 0 ]]; then
echo "${__ErrMsgPrefix}Failed to generate native version file."
exit "$exit_code"
fi
else
# Generate the dummy version.c and runtime_version.h, but only if they didn't exist to make sure we don't trigger unnecessary rebuild
__versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
if [[ -e "$__versionSourceFile" ]]; then
read existingVersionSourceLine < "$__versionSourceFile"
fi
if [[ "$__versionSourceLine" != "$existingVersionSourceLine" ]]; then
cat << EOF > $runtimeVersionHeaderFile
#define RuntimeAssemblyMajorVersion 0
#define RuntimeAssemblyMinorVersion 0
#define RuntimeFileMajorVersion 0
#define RuntimeFileMinorVersion 0
#define RuntimeFileBuildVersion 0
#define RuntimeFileRevisionVersion 0
#define RuntimeProductMajorVersion 0
#define RuntimeProductMinorVersion 0
#define RuntimeProductPatchVersion 0
#define RuntimeProductVersion
EOF
echo "$__versionSourceLine" > "$__versionSourceFile"
fi
fi

if [[ "$__StaticAnalyzer" == 1 ]]; then
scan_build=scan-build
Expand Down Expand Up @@ -243,12 +182,10 @@ usage()
echo " will use ROOTFS_DIR environment variable if set."
echo "-gcc: optional argument to build using gcc in PATH."
echo "-gccx.y: optional argument to build using gcc version x.y."
echo "-msbuildonunsupportedplatform: build managed binaries even if distro is not officially supported."
echo "-ninja: target ninja instead of GNU make"
echo "-numproc: set the number of build processes."
echo "-portablebuild: pass -portablebuild=false to force a non-portable build."
echo "-skipconfigure: skip build configuration."
echo "-skipgenerateversion: disable version generation even if MSBuild is supported."
echo "-keepnativesymbols: keep native/unmanaged debug symbols."
echo "-verbose: optional argument to enable verbose build output."
echo ""
Expand All @@ -269,8 +206,6 @@ __TargetOS=$os
__HostOS=$os
__BuildOS=$os

__msbuildonunsupportedplatform=0

# Get the number of processors available to the scheduler
# Other techniques such as `nproc` only get the number of
# processors available to a single process.
Expand Down Expand Up @@ -389,10 +324,6 @@ while :; do
__CMakeArgs="$__CMakeArgs -DCLR_CMAKE_KEEP_NATIVE_SYMBOLS=true"
;;

msbuildonunsupportedplatform|-msbuildonunsupportedplatform)
__msbuildonunsupportedplatform=1
;;

ninja|-ninja)
__UseNinja=1
;;
Expand All @@ -419,10 +350,6 @@ while :; do
__SkipConfigure=1
;;

skipgenerateversion|-skipgenerateversion)
__SkipGenerateVersion=1
;;

verbose|-verbose)
__VerboseBuild=1
;;
Expand Down Expand Up @@ -507,6 +434,3 @@ fi

# init the target distro name
initTargetDistroRid

# Init if MSBuild for .NET Core is supported for this platform
isMSBuildOnNETCoreSupported
5 changes: 5 additions & 0 deletions eng/native/configurepaths.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ get_filename_component(CLR_REPO_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../.. ABSOLUT
set(CLR_ENG_NATIVE_DIR ${CMAKE_CURRENT_LIST_DIR})
get_filename_component(CLR_SRC_NATIVE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../src/native ABSOLUTE)
get_filename_component(CLR_SRC_LIBS_NATIVE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../src/libraries/Native ABSOLUTE)
set (CLR_ARTIFACTS_OBJ_DIR "${CLR_REPO_ROOT_DIR}/artifacts/obj")
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
set(VERSION_HEADER_PATH "${CLR_ARTIFACTS_OBJ_DIR}/_version.h")
set(VERSION_FILE_PATH "${CLR_ARTIFACTS_OBJ_DIR}/_version.c")
set(VERSION_FILE_RC_PATH "${CLR_ARTIFACTS_OBJ_DIR}/NativeVersion.rc")
set(RUNTIME_VERSION_HEADER_PATH "${CLR_ARTIFACTS_OBJ_DIR}/runtime_version.h")
41 changes: 41 additions & 0 deletions eng/native/version/NativeVersion.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "_version.h"

#include <windows.h>

VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILEVERSION
PRODUCTVERSION VER_PRODUCTVERSION
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEFLAGS VER_DEBUG
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904E4"
BEGIN
VALUE "CompanyName", VER_COMPANYNAME_STR
VALUE "FileDescription", VER_FILEDESCRIPTION_STR
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "InternalName", VER_INTERNALNAME_STR
VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR
VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR
VALUE "ProductName", VER_PRODUCTNAME_STR
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
END
END

BLOCK "VarFileInfo"
BEGIN
/* The following line should only be modified for localized versions. */
/* It consists of any number of WORD,WORD pairs, with each pair */
/* describing a language,codepage combination supported by the file. */
/* */
/* For example, a file might have values "0x409,1252" indicating that it */
/* supports English language (0x409) in the Windows ANSI codepage (1252). */

VALUE "Translation", 0x409, 1252

END
END
4 changes: 4 additions & 0 deletions eng/native/version/_version.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

static char sccsid[] __attribute__((used)) = "@(#)No version information produced";
29 changes: 29 additions & 0 deletions eng/native/version/_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef VER_COMPANYNAME_STR
#define VER_COMPANYNAME_STR ".NET Foundation"
#endif
#ifndef VER_FILEDESCRIPTION_STR
#define VER_FILEDESCRIPTION_STR ".NET Runtime"
#endif
#ifndef VER_INTERNALNAME_STR
#define VER_INTERNALNAME_STR VER_FILEDESCRIPTION_STR
#endif
#ifndef VER_ORIGINALFILENAME_STR
#define VER_ORIGINALFILENAME_STR VER_FILEDESCRIPTION_STR
#endif
#ifndef VER_PRODUCTNAME_STR
#define VER_PRODUCTNAME_STR ".NET"
#endif
#undef VER_PRODUCTVERSION
#define VER_PRODUCTVERSION 00,00,00,00000
#undef VER_PRODUCTVERSION_STR
#define VER_PRODUCTVERSION_STR "0.0.0"
#undef VER_FILEVERSION
#define VER_FILEVERSION 00,00,00,00000
#undef VER_FILEVERSION_STR
#define VER_FILEVERSION_STR "00,00,00,00000"
#ifndef VER_LEGALCOPYRIGHT_STR
#define VER_LEGALCOPYRIGHT_STR ".NET Foundation"
#endif
#ifndef VER_DEBUG
#define VER_DEBUG VS_FF_DEBUG
#endif
12 changes: 12 additions & 0 deletions eng/native/version/copy_version_files.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@if not defined _echo @echo off
setlocal EnableDelayedExpansion EnableExtensions

set __VersionFolder=%~dp0
set __RepoRoot=%~dp0..\..\..
set __artifactsObjDir=%__RepoRoot%\artifacts\obj

for /r "%__VersionFolder%" %%a in (*.h *.rc) do (
if not exist "%__artifactsObjDir%\%%~nxa" (
copy "%%a" "%__artifactsObjDir%"
)
)
21 changes: 21 additions & 0 deletions eng/native/version/copy_version_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
__VersionFolder="$(cd "$(dirname "$0")"; pwd -P)"
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
__RepoRoot="$(cd "$(dirname "$__VersionFolder")/../../"; pwd -P)"

for path in "${__VersionFolder}/"*{.h,.c}; do
if [[ "$(basename $path)" == _version.c ]]; then
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
# For _version.c, update the commit ID if it has changed from the last build.
# Set IFS to nothing to prevent the shell from combining all of the piped output into a single line in the script below
IFS=
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, is it cat jumbling the lines?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's bash jumbling the lines that are outputted from cat and sed.

# update commit
commit="$(git rev-parse HEAD 2>/dev/null)"
commit="${commit:-N/A}"
substitute="$(printf 'static char sccsid[] __attribute__((used)) = "@(#)Version N/A @Commit: %s";\n' "$commit")"
version_file_contents=$(cat $path | sed "s|^static.*|$substitute|")
version_file_destination=$__RepoRoot/artifacts/obj/_version.c
if [[ ! -e "$version_file_destination" || "$version_file_contents" != "$(<"$__RepoRoot/artifacts/obj/_version.c")" ]]; then
echo $version_file_contents > "$version_file_destination"
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
fi
elif [[ ! -e "$__RepoRoot/artifacts/obj/$(basename "$path")" ]]; then
cp "$path" "$__RepoRoot/artifacts/obj/"
fi
done
10 changes: 10 additions & 0 deletions eng/native/version/runtime_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#define RuntimeAssemblyMajorVersion 0
#define RuntimeAssemblyMinorVersion 0
#define RuntimeFileMajorVersion 0
#define RuntimeFileMinorVersion 0
#define RuntimeFileBuildVersion 0
#define RuntimeFileRevisionVersion 0
#define RuntimeProductMajorVersion 0
#define RuntimeProductMinorVersion 0
#define RuntimeProductPatchVersion 0
#define RuntimeProductVersion
56 changes: 56 additions & 0 deletions eng/nativepgo.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<Project>
<PropertyGroup>
<NativeOptimizationDataSupported Condition="'$(TargetOS)' == 'windows' And ('$(TargetArchitecture)' == 'x64' Or '$(TargetArchitecture)' == 'x86')">true</NativeOptimizationDataSupported>
<NativeOptimizationDataSupported Condition="'$(TargetOS)' == 'Linux' And '$(TargetArchitecture)' == 'x64'">true</NativeOptimizationDataSupported>
<NativeOptimizationDataSupported Condition="'$(NoPgoOptimize)' == 'true'">false</NativeOptimizationDataSupported>
<NativeOptimizationDataSupported Condition="'$(DotNetBuildFromSource)' == 'true'">false</NativeOptimizationDataSupported>
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved

<_NativeOptimizationDataPackageTarget>$(TargetOS.ToLower())-$(TargetArchitecture.ToLower())</_NativeOptimizationDataPackageTarget>
<_NativeOptimizationDataPackageTarget Condition="'$(TargetOS)' == 'windows'">windows_nt-$(TargetArchitecture.ToLower())</_NativeOptimizationDataPackageTarget>

</PropertyGroup>
<ItemGroup>
<PackageReference Include="optimization.$(_NativeOptimizationDataPackageTarget).PGO.CoreCLR"
Version="$(optimizationPGOCoreCLRVersion)"
Condition="'$(optimizationPGOCoreCLRVersion)'!='' And '$(NativeOptimizationDataSupported)'!=''"
GeneratePathProperty="true" />
</ItemGroup>


<!-- -->
<!-- Task: GetPgoDataPackagePath -->
<!-- -->
<!-- Notes: -->
<!-- -->
<!-- DumpPgoDataPackagePath is used to get the path of the native PGO data -->
<!-- for other MSBuild projects, generally to pass to another project or -->
<!-- native script like build-runtime.cmd/sh. -->
<!-- -->

<Target Name="GetPgoDataPackagePath" Returns="$(PgoPackagePath)">
<PropertyGroup>
<PgoPackagePathProperty>Pkgoptimization_$(_NativeOptimizationDataPackageTarget)_PGO_CoreCLR</PgoPackagePathProperty>
</PropertyGroup>

<!--
Use an item group for expansion of $($(PgoPackagePathProperty)) (an illegal MSBuild expression)
i.e. the prop value's value.
-->
<ItemGroup>
<PgoPackagePathPropertyItemList Include="$(PgoPackagePathProperty)" />
<PgoPackagePathPropertyItemList>
<PgoPackagePath>$(%(Identity))</PgoPackagePath>
</PgoPackagePathPropertyItemList>
</ItemGroup>

<PropertyGroup>
<PgoPackagePath>@(PgoPackagePathPropertyItemList->'%(PgoPackagePath)')</PgoPackagePath>
</PropertyGroup>

<Error Condition="!Exists('$(PgoPackagePath)') And '$(NativeOptimizationDataSupported)' == 'true'" Text="Unable to locate restored PGO package at $(PgoPackagePath). Maybe the platform-specific package naming changed?" />
</Target>

<Target Name="OutputPgoPathForCI" Condition="'$(ContinuousIntegrationBuild)' == 'true' and '$(NativeOptimizationDataSupported)' == 'true'" DependsOnTargets="GetPgoDataPackagePath">
<Message Text="##vso[task.setvariable variable=CoreClrPgoDataArg]-pgodatapath &quot;$(PgoPackagePath)&quot;" Importance="High" />
</Target>
</Project>
Loading