Skip to content

Commit 8566685

Browse files
authored
Enable PlatformNativeR2R test on macOS (#121752)
- Allow setting `Crossgen2OutputFormat` in tests - passed as `-f <format>` to crossgen2 - Update generated test scripts to handle Mach-O output format for crossgen2, linking the produced object into a dynamic library - Enable `PlatformNativeR2R` test on macOS and set format to `macho`
1 parent 7d37868 commit 8566685

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

src/tests/Common/CLRTest.CrossGen.targets

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ if [ ! -z ${RunCrossGen2+x} ]%3B then
6060
if [ ! -d IL-CG2 ]%3B then
6161
mkdir IL-CG2
6262
cp ./*.dll IL-CG2/
63-
rm IL-CG2/composite-r2r.dll 2>/dev/null
63+
rm IL-CG2/composite-r2r.* 2>/dev/null
6464
rm IL-CG2/Coreclr.TestWrapper.dll 2>/dev/null
6565
rm IL-CG2/*.XUnitWrapper.dll 2>/dev/null
6666
@@ -85,6 +85,7 @@ if [ ! -z ${RunCrossGen2+x} ]%3B then
8585
RunCrossgen2OnFiles() {
8686
date +%H:%M:%S
8787
__OutputFile=$1
88+
__OutputFileFinal=$2
8889
8990
__ResponseFile="$__OutputFile.rsp"
9091
rm "$__ResponseFile" 2>/dev/null
@@ -97,14 +98,17 @@ if [ ! -z ${RunCrossGen2+x} ]%3B then
9798
__R2RDumpCommand+=" dotnet"
9899
fi
99100
__R2RDumpCommand+=" $CORE_ROOT/R2RDump/R2RDump.dll"
100-
__R2RDumpCommand+=" --header --sc --in $__OutputFile --out $__OutputFile.r2rdump --val"
101+
__R2RDumpCommand+=" --header --sc --in $__OutputFileFinal --out $__OutputFileFinal.r2rdump --val"
101102
102103
__Command="$_DebuggerFullPath $CORE_ROOT/crossgen2/crossgen2"
103104
__Command+=" @$__ResponseFile"
104105
__Command+=" $ExtraCrossGen2Args"
106+
if [ -n "$(CrossGen2OutputFormat)" ]; then
107+
__Command+=" -f $(CrossGen2OutputFormat)"
108+
fi
105109
106110
# Expand glob or multiple filenames into array
107-
__InputFiles=($2)
111+
__InputFiles=($3)
108112
for dllFile in "${__InputFiles[@]}"; do
109113
echo "$dllFile" >> "$__ResponseFile"
110114
done
@@ -148,6 +152,14 @@ if [ ! -z ${RunCrossGen2+x} ]%3B then
148152
$__Command
149153
__cg2ExitCode=$?
150154
155+
__linkExitCode=0
156+
if [ "$(CrossGen2OutputFormat)" == "macho" ]; then
157+
echo "Linking: $(basename "$__OutputFile") -> $(basename "$__OutputFileFinal")"
158+
echo clang -dynamiclib -o "$__OutputFileFinal" "$__OutputFile" -install_name "@rpath/`basename "$__OutputFileFinal"`" -Wl,-dead_strip
159+
clang -dynamiclib -o "$__OutputFileFinal" "$__OutputFile" -install_name "@rpath/`basename "$__OutputFileFinal"`" -Wl,-dead_strip
160+
__linkExitCode=$?
161+
fi
162+
151163
echo "Running R2RDump: $__R2RDumpCommand"
152164
$__R2RDumpCommand
153165
__r2rDumpExitCode=$?
@@ -159,7 +171,13 @@ if [ ! -z ${RunCrossGen2+x} ]%3B then
159171
160172
if [ ! -z ${CompositeBuildMode+x} ]%3B then
161173
shopt -s nullglob
162-
RunCrossgen2OnFiles "$PWD/composite-r2r.dll" "$PWD/IL-CG2/*.dll"
174+
__CompositeExt=".dll"
175+
__CompositeExtFinal=".dll"
176+
if [ "$(CrossGen2OutputFormat)" == "macho" ]; then
177+
__CompositeExt=".o"
178+
__CompositeExtFinal=".dylib"
179+
fi
180+
RunCrossgen2OnFiles "$PWD/composite-r2r${__CompositeExt}" "$PWD/composite-r2r${__CompositeExtFinal}" "$PWD/IL-CG2/*.dll"
163181
else
164182
ExtraCrossGen2Args+=" -r:$PWD/IL-CG2/*.dll"
165183
for dllFile in "$PWD"/IL-CG2/*.dll
@@ -184,6 +202,11 @@ if [ ! -z ${RunCrossGen2+x} ]%3B then
184202
ReleaseLock
185203
exit 1
186204
fi
205+
if [ $__linkExitCode -ne 0 ]; then
206+
echo "Linking failed with exitcode: $__linkExitCode"
207+
ReleaseLock
208+
exit 1
209+
fi
187210
fi
188211
ReleaseLock
189212
fi
@@ -230,7 +253,7 @@ if defined RunCrossGen2 (
230253
231254
mkdir IL-CG2
232255
copy *.dll IL-CG2\
233-
del IL-CG2\composite-r2r.dll 2>nul
256+
del IL-CG2\composite-r2r.* 2>nul
234257
del IL-CG2\Coreclr.TestWrapper.dll 2>nul
235258
del IL-CG2\*.XUnitWrapper.dll 2>nul
236259

src/tests/Loader/PlatformNativeR2R/PlatformNativeR2R.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public static void EntryPoint()
4545
}
4646

4747
Assert.True(output.Contains("READYTORUN_FLAG_Component"), "Component assembly should be associated with a platform-native composite image");
48-
// TODO: Uncomment assert when crossgen2 adds support for the flag
49-
// Assert.True(output.Contains("READYTORUN_FLAG_PlatformNativeImage"), "Component assembly should be associated with a platform-native composite image");
48+
Assert.True(output.Contains("READYTORUN_FLAG_PlatformNativeImage"), "Component assembly should be associated with a platform-native composite image");
5049
}
5150
}
5251
}

src/tests/Loader/PlatformNativeR2R/PlatformNativeR2R.csproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
<RequiresProcessIsolation>true</RequiresProcessIsolation>
55
<!-- Explictly testing R2R composite format -->
66
<AlwaysUseCrossGen2>true</AlwaysUseCrossGen2>
7-
<!-- TODO: Enable for macOS and pass -f macho as arguments -->
8-
<CLRTestTargetUnsupported Condition="'$(TargetsWindows)' != 'true'">true</CLRTestTargetUnsupported>
9-
<!-- <CLRTestTargetUnsupported Condition="'$(TargetsWindows)' != 'true' and '$(TargetsOSX)' != 'true' and '$(TargetsAppleMobile)' != 'true'">true</CLRTestTargetUnsupported> -->
10-
<!-- <CrossGen2TestExtraArguments Condition="'$(TargetsOSX)' == 'true' or '$(TargetsAppleMobile)' == 'true'">-f macho</CrossGen2TestExtraArguments> -->
7+
<CLRTestTargetUnsupported Condition="'$(TargetsWindows)' != 'true' and '$(TargetsOSX)' != 'true' and '$(TargetsAppleMobile)' != 'true'">true</CLRTestTargetUnsupported>
8+
<CrossGen2OutputFormat Condition="'$(TargetsOSX)' == 'true' or '$(TargetsAppleMobile)' == 'true'">macho</CrossGen2OutputFormat>
119
</PropertyGroup>
1210
<ItemGroup>
1311
<Compile Include="PlatformNativeR2R.cs" />

0 commit comments

Comments
 (0)