Skip to content

Commit

Permalink
Fix crossgenning of framework libraries on Windows (#747)
Browse files Browse the repository at this point in the history
1) Fix crossgenning of framework libraries on Windows;

2) Enable crossgenning S.P.C with CG2, remove obsolete CoreCLR logic;

3) Fix framework build with legacy Crossgen due to a typo in my change;

4) The ordering of steps in build-test was incorrect - we need to
patch CORE_ROOT with live-live libraries build before Crossgenning
the framework therein, otherwise weird things happen (and the result
is incorrect in any case).

5) Removed misplaced >nul 2>nul - we agreed with JanV that it's
better to not throw diagnostic information away.

6) Applied JanV's suggestion for improvement - using a tighter filter
for reference assemblies - Microsoft.*.dll / System.*.dll /
mscorlib.dll instead of just *.dll that ended up picking tons of
garbage like clrjit.dll and the various Win32 API contracts, both
in the build-test script and in CLRTest.Crossgen.targets.

Thanks

Tomas
  • Loading branch information
trylek authored Dec 14, 2019
1 parent 6a620e6 commit ac4b5b6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 25 deletions.
66 changes: 43 additions & 23 deletions src/coreclr/build-test.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,21 @@ echo { "build_os": "%__BuildOS%", "build_arch": "%__BuildArch%", "build_type": "

:SkipBuildingWrappers

REM =========================================================================================
REM ===
REM === Copy CoreFX assemblies if needed.
REM ===
REM =========================================================================================

if NOT "%__LocalCoreFXPath%"=="" (
echo Patch CoreFX from %__LocalCoreFXPath% ^(%__LocalCoreFXConfig%^)
set NEXTCMD=python "%__ProjectDir%\tests\scripts\patch-corefx.py" -clr_core_root "%CORE_ROOT%"^
-fx_root "%__LocalCoreFXPath%" -arch %__BuildArch% -build_type %__LocalCoreFXConfig%
echo !NEXTCMD!
!NEXTCMD!
)


REM =========================================================================================
REM ===
REM === Crossgen assemblies if needed.
Expand All @@ -516,7 +531,7 @@ set __CrossgenArg = ""
if defined __DoCrossgen (
set __CrossgenArg="/p:Crossgen=true"
if "%__TargetsWindows%" == "1" (
echo %__MsgPrefix%Running crossgen on framework assemblies
echo %__MsgPrefix%Running crossgen on framework assemblies in CORE_ROOT: %CORE_ROOT%
call :PrecompileFX
) else (
echo "%__MsgPrefix%Crossgen only supported on Windows, for now"
Expand All @@ -526,7 +541,7 @@ if defined __DoCrossgen (
if defined __DoCrossgen2 (
set __CrossgenArg="/p:Crossgen2=true"
if "%__BuildArch%" == "x64" (
echo %__MsgPrefix%Running crossgen2 on framework assemblies
echo %__MsgPrefix%Running crossgen2 on framework assemblies in CORE_ROOT: %CORE_ROOT%
call :PrecompileFX
) else (
echo "%__MsgPrefix%Crossgen2 only supported on x64, for now"
Expand Down Expand Up @@ -609,51 +624,56 @@ exit /b 0
REM Compile the managed assemblies in Core_ROOT before running the tests
:PrecompileAssembly

REM Skip mscorlib since it is already precompiled.
if /I "%2" == "mscorlib.dll" exit /b 0
if /I "%2" == "mscorlib.ni.dll" exit /b 0
REM don't precompile anything from CoreCLR
if /I exist %CORE_ROOT_STAGE%\%2 exit /b 0
set AssemblyPath=%1
set AssemblyName=%2

REM Don't precompile xunit.* files
echo "%2" | findstr /b "xunit." >nul && (
echo "%AssemblyName%" | findstr /b "xunit." >nul && (
exit /b 0
)

set __CrossgenExe="%CORE_ROOT_STAGE%\crossgen.exe"
if /i "%__BuildArch%" == "arm" ( set __CrossgenExe="%CORE_ROOT_STAGE%\x86\crossgen.exe" )
if /i "%__BuildArch%" == "arm64" ( set __CrossgenExe="%CORE_ROOT_STAGE%\x64\crossgen.exe" )
REM Skip the Win32 API dll's
if /i "%AssemblyName:~0,4%"=="api-" exit /b 0

set __CrossgenExe="%CORE_ROOT%\crossgen.exe"
if /i "%__BuildArch%" == "arm" ( set __CrossgenExe="%CORE_ROOT%\x86\crossgen.exe" )
if /i "%__BuildArch%" == "arm64" ( set __CrossgenExe="%CORE_ROOT%\x64\crossgen.exe" )
set __CrossgenExe=%__CrossgenExe%

if defined __DoCrossgen2 (
set __CrossgenExe="%CORE_ROOT_STAGE%\crossgen2\crossgen2.exe"
set __CrossgenExe="%CORE_ROOT%\crossgen2\crossgen2.exe"
)

set __CrossgenOutputFile="%CORE_ROOT%\temp.ni.dll"
REM Intentionally avoid using the .dll extension to prevent
REM subsequent compilations from picking it up as a reference
set __CrossgenOutputFile="%CORE_ROOT%\temp.ni._dll"
set __CrossgenCmd=

if defined __Crossgen (
"!__CrossgenExe!" /Platform_Assemblies_Paths "!CORE_ROOT!" /in "%1" /out "!__CrossgenOutputFile" >nul 2>nul
set /a __exitCode = !errorlevel!
if defined __DoCrossgen (
set __CrossgenCmd=!__CrossgenExe! /Platform_Assemblies_Paths "!CORE_ROOT!" /in !AssemblyPath! /out !__CrossgenOutputFile!
) else (
"!CORE_ROOT_STAGE!\crossgen2\crossgen2 -r:"!CORE_ROOT!\*.dll" -O --inputbubble -out:"__CrossgenOutputFile" "%1" >nul 2>nul
set /a __exitCode = !errorlevel!
set __CrossgenCmd=!__CrossgenExe! -r:"!CORE_ROOT!\System.*.dll" -r:"!CORE_ROOT!\Microsoft.*.dll" -r:"!CORE_ROOT!\mscorlib.dll" -O --inputbubble --out:!__CrossgenOutputFile! !AssemblyPath!
)

echo %__CrossgenCmd%
%__CrossgenCmd%
set /a __exitCode = !errorlevel!

if "%__exitCode%" == "-2146230517" (
echo %2 is not a managed assembly.
echo %AssemblyPath% is not a managed assembly.
exit /b 0
)

if %__exitCode% neq 0 (
echo Unable to precompile %2, Exit Code is %__exitCode%
echo Unable to precompile %AssemblyPath%, Exit Code is %__exitCode%
exit /b 0
)

REM Delete original .dll & replace it with the Crossgened .dll
del %1
ren "%__CrossgenOutputFile%" %2
del %AssemblyPath%
ren "%__CrossgenOutputFile%" %AssemblyName%

echo Successfully precompiled %2
echo Successfully precompiled %AssemblyPath%
exit /b 0

:Exit_Failure
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/build-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ build_Tests()
fi

if [ $__SkipGenerateLayout != 1 ]; then
if [ ! -z "$__LocalCoreFXPath" ]; then
patch_corefx_libraries
fi

generate_layout
fi
}
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/tests/src/CLRTest.CrossGen.targets
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ if [ ! -z ${RunCrossGen2+x} ]%3B then
mkdir IL
cp $(MSBuildProjectName).dll IL/$(MSBuildProjectName).dll
mv $(MSBuildProjectName).dll $(MSBuildProjectName).org
__Command=$_DebuggerFullPath "$CORE_ROOT/crossgen2/crossgen2" -r:$CORE_ROOT/*.dll -r:$PWD/*.dll --targetarch=x64 -O --inputbubble -o:$(scriptPath)$(MSBuildProjectName).dll $(scriptPath)$(MSBuildProjectName).org
__Command=$_DebuggerFullPath "$CORE_ROOT/crossgen2/crossgen2" -r:$CORE_ROOT/System.*.dll -r:$CORE_ROOT/Microsoft.*.dll -r:$CORE_ROOT/mscorlib.dll -r:$PWD/*.dll --targetarch=x64 -O --inputbubble -o:$(scriptPath)$(MSBuildProjectName).dll $(scriptPath)$(MSBuildProjectName).org
echo $__Command
$__Command
__cg2ExitCode=$?
Expand Down Expand Up @@ -132,7 +132,7 @@ if defined RunCrossGen2 (
mkdir IL
copy $(MSBuildProjectName).dll IL\$(MSBuildProjectName).dll
ren $(MSBuildProjectName).dll $(MSBuildProjectName).org
set __Command=!_DebuggerFullPath! "!CORE_ROOT!\crossgen2\crossgen2" %21scriptPath%21$(MSBuildProjectName).org -o:%21scriptPath%21$(MSBuildProjectName).dll --targetarch:x64 -O --inputbubble -r:!CORE_ROOT!\*.dll -r:%25cd%25\*.dll
set __Command=!_DebuggerFullPath! "!CORE_ROOT!\crossgen2\crossgen2" %21scriptPath%21$(MSBuildProjectName).org -o:%21scriptPath%21$(MSBuildProjectName).dll --targetarch:x64 -O --inputbubble -r:"!CORE_ROOT!\System.*.dll" -r:"!CORE_ROOT!\Microsoft.*.dll" -r:"!CORE_ROOT!\mscorlib.dll" -r:%25cd%25\*.dll
echo "!__Command!"
call !__Command!
set CrossGen2Status=!ERRORLEVEL!
Expand Down

0 comments on commit ac4b5b6

Please sign in to comment.