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

Unify linking file composition for wasi and wasm. #107547

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 src/mono/browser/build/BrowserWasmApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@

<_WasmNativeFileForLinking Include="%(_BitcodeFile.ObjectFile)" />
<_WasmNativeFileForLinking Include="%(_WasmSourceFileToCompile.ObjectFile)" />
<_WasmNativeFileForLinking Include="@(_WasmObjectFilesForBundle)" />
<_WasmNativeFileForLinking Include="%(_WasmObjectFilesForBundle.RelativePath)" />

<_WasmNativeFileForLinking
Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)*.a"
Expand Down
14 changes: 2 additions & 12 deletions src/mono/wasi/build/WasiApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -313,19 +313,9 @@
<_MonoRuntimeComponentDontLink Include="libmono-component-diagnostics_tracing-static.a" Condition="'$(UsingWasiRuntimeWorkload)' != 'true'" /> <!-- Just for in-tree build + CI -->
</ItemGroup>

<ItemGroup>
<!-- using relative paths fixes https://github.com/dotnet/runtime/issues/106845 -->
<RelativeBitcodeFiles Include="%(_BitcodeFile.ObjectFile)" Condition="'%(_BitcodeFile.ObjectFile)' != ''">
<RelativePath>$([System.IO.Path]::GetRelativePath('$(MSBuildProjectDirectory)', '%(Identity)'))</RelativePath>
</RelativeBitcodeFiles>
<RelativeWasmObjectFiles Include="@(_WasmObjectFilesForBundle)" Condition="'%(_WasmObjectFilesForBundle.Identity)' != ''">
<RelativePath>$([System.IO.Path]::GetRelativePath('$(MSBuildProjectDirectory)', '%(Identity)'))</RelativePath>
</RelativeWasmObjectFiles>
</ItemGroup>

<ItemGroup>
<!-- order matters -->
<_WasmNativeFileForLinking Include="%(RelativeBitcodeFiles.RelativePath)" />
<_WasmNativeFileForLinking Include="%(_BitcodeFile.RelativePath)" />
<!--<_WasmNativeFileForLinking Include="%(_WasmSourceFileToCompile.ObjectFile)" />-->

<_WasmNativeFileForLinking
Expand All @@ -345,7 +335,7 @@
<ItemGroup>
<_WasiClangXLinkerFlags Include="--initial-memory=$(WasmInitialHeapSize)" />
<_WasiFilePathForFixup Include="$(_WasiGetEntrypointCFile)" />
<_WasiFilePathForFixup Include="%(RelativeWasmObjectFiles.RelativePath)" />
<_WasiFilePathForFixup Include="%(_WasmObjectFilesForBundle.RelativePath)" />
<_WasiFilePathForFixup Include="@(_WasmNativeFileForLinking)" />

<_WasmLinkDependencies Include="@(_WasiFilePathForFixup)" />
Expand Down
3 changes: 2 additions & 1 deletion src/mono/wasm/Wasm.Build.Tests/BuildProjectOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ public record BuildProjectOptions
string? MainJS = null,
bool IsBrowserProject = true,
IDictionary<string, string>? ExtraBuildEnvironmentVariables = null,
string? BinFrameworkDir = null
string? BinFrameworkDir = null,
string? ProjectParentDir = null
);
20 changes: 20 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,26 @@ void Run(bool expectAOT) => RunAndTestWasmApp(
host: host, id: id);
}

[Theory]
[BuildAndRun(host: RunHost.None, aot: false, config: "Release")]
public void BuildInLongPathNative(BuildArgs buildArgs, string id)
{
string projectName = GetTestProjectPath(prefix: "long_path", config: buildArgs.Config, appendUnicode: false);

buildArgs = buildArgs with { ProjectName = projectName, ExtraBuildArgs = "-p:WasmBuildNative=true" };
buildArgs = ExpandBuildArgs(buildArgs);

(_, string output) = BuildProject(buildArgs,
id,
new BuildProjectOptions(
InitProject: () => File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), s_mainReturns42),
DotnetWasmFromRuntimePack: false,
CreateProject: true,
Publish: false,
ProjectParentDir: Path.Combine("reallyLongPath", "toProlongPathsToLinkedFiles", "andMakeTheResultingLinkingCommandExtremelyLong")));

}

void CheckOutputForNativeBuild(bool expectAOT, bool expectRelinking, BuildArgs buildArgs, string buildOutput, bool testUnicode)
{
if (testUnicode)
Expand Down
13 changes: 11 additions & 2 deletions src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,19 @@ protected static string RunWithXHarness(string testCommand, string testLogPath,
}

[MemberNotNull(nameof(_projectDir), nameof(_logPath))]
protected void InitPaths(string id)
protected void InitPaths(string id, string? projectParentDir = null)
{
if (_projectDir == null)
_projectDir = Path.Combine(BuildEnvironment.TmpPath, id);
{
if (projectParentDir == null)
{
_projectDir = Path.Combine(BuildEnvironment.TmpPath, id);
}
else
{
_projectDir = Path.Combine(BuildEnvironment.TmpPath, projectParentDir, id);
}
}
_logPath = Path.Combine(s_buildEnv.LogRootPath, id);
_nugetPackagesDir = Path.Combine(BuildEnvironment.TmpPath, "nuget", id);

Expand Down
11 changes: 8 additions & 3 deletions src/mono/wasm/build/WasmApp.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,10 @@
</ItemGroup>

<ItemGroup>
<_BitcodeFile Include="%(_WasmAssembliesInternal.LlvmBitcodeFile)" />
<_BitcodeFile ObjectFile="$(_WasmIntermediateOutputPath)%(FileName).o" />
<_BitcodeFile Include="%(_WasmAssembliesInternal.LlvmBitcodeFile)">
<ObjectFile>$(_WasmIntermediateOutputPath)%(FileName).o</ObjectFile>
<RelativePath>$([System.IO.Path]::GetRelativePath('$(MsBuildProjectDirectory)', '%(LlvmBitCodeFile)'))</RelativePath>
</_BitcodeFile>

<!-- Add the skipped assemblies -->
<_WasmAssembliesInternal Include="@(_AotInputAssemblies->WithMetadataValue('AOT_InternalForceToInterpret', 'true'))" />
Expand Down Expand Up @@ -908,7 +910,9 @@
<_EmitBundleOutputFile Include="%(_EmitBundleOutputItem.DestinationFile)" />
<_EmitBundleOutputFile Include="@(_EmitBundleRegistrationFile)" />

<_WasmObjectFilesForBundle Include="@(_EmitBundleOutputFile)" />
<_WasmObjectFilesForBundle Include="@(_EmitBundleOutputFile)">
<RelativePath Condition="'%(_EmitBundleOutputFile.Identity)' != ''">$([System.IO.Path]::GetRelativePath('$(MSBuildProjectDirectory)', '%(Identity)'))</RelativePath>
</_WasmObjectFilesForBundle>
<FileWrites Include="@(_EmitBundleOutputFile)" />
</ItemGroup>
</Target>
Expand All @@ -918,6 +922,7 @@
<Target Name="_CheckToolchainIsExpectedVersion" />

<Target Name="_WasmWriteRspForLinking">
<!-- HERE, how stripped landed here? -->
<WriteLinesToFile Lines="@(_WasmLinkStepArgs)" File="$(_WasmLinkRsp)" Overwrite="true" WriteOnlyWhenDifferent="true" />
<ItemGroup>
<FileWrites Include="$(_WasmLinkRsp)" />
Expand Down
Loading