Skip to content

Don't serialize relative resource dir paths in swiftmodules #76964

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

Merged
merged 1 commit into from
Oct 14, 2024
Merged
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
8 changes: 7 additions & 1 deletion lib/Frontend/ModuleInterfaceBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ bool ExplicitModuleInterfaceBuilder::collectDepsForSerialization(
path::native(SDKPath);
SmallString<128> ResourcePath(Opts.RuntimeResourcePath);
path::native(ResourcePath);
// When compiling with a relative resource dir, the clang
// importer will track inputs with absolute paths. To avoid
// serializing resource dir inputs we need to check for
// relative _and_ absolute prefixes.
SmallString<128> AbsResourcePath(ResourcePath);
llvm::sys::fs::make_absolute(AbsResourcePath);

auto DTDeps = Instance.getDependencyTracker()->getDependencies();
SmallVector<std::string, 16> InitialDepNames(DTDeps.begin(), DTDeps.end());
Expand Down Expand Up @@ -146,7 +152,7 @@ bool ExplicitModuleInterfaceBuilder::collectDepsForSerialization(
}

// Don't serialize compiler-relative deps so the cache is relocatable.
if (DepName.starts_with(ResourcePath))
if (DepName.starts_with(ResourcePath) || DepName.starts_with(AbsResourcePath))
continue;

auto Status = fs.status(DepName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Name: ClangModule
Globals:
- Name: CMThing
SwiftName: SwiftThing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
struct CMThing {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module ClangModule [system] {
header "ClangModuleHeader.h"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// swift-module-flags: -target arm64-apple-macosx15.0 -module-name OtherModule -O

import Swift
import ClangModule

public struct OtherStruct {
var x : Int
Expand Down
13 changes: 13 additions & 0 deletions test/ModuleInterface/relative-resource-path.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// REQUIRES: OS=macosx

// RUN: %empty-directory(%t.relative_resource_path)
// RUN: %empty-directory(%t.mcp)
// RUN: cp -R %S/Inputs/resource_dir %t.relative_resource_path/
// RUN: cd %t.relative_resource_path

// RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs/stdlib_rebuild -module-cache-path %t.mcp) -target arm64-apple-macosx15.0 \
// RUN: -resource-dir resource_dir -compile-module-from-interface -o OtherModule.swiftmodule \
// RUN: %S/Inputs/stdlib_rebuild/usr/lib/swift/OtherModule.swiftmodule/arm64-apple-macos.swiftinterface
// RUN: llvm-bcanalyzer -dump OtherModule.swiftmodule | %FileCheck %s

// CHECK-NOT: <DEPENDENCY_DIRECTORY abbrevid=11/> blob data = '/