Skip to content

Commit b8a0d30

Browse files
committed
Use dsymutil to rebuild DWARF debug symbols
1 parent 97c6316 commit b8a0d30

File tree

1 file changed

+49
-10
lines changed

1 file changed

+49
-10
lines changed

packages/host/src/node/cli/apple.ts

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const XcframeworkInfoSchema = zod.looseObject({
5959
BinaryPath: zod.string(),
6060
LibraryIdentifier: zod.string(),
6161
LibraryPath: zod.string(),
62+
DebugSymbolsPath: zod.string().optional(),
6263
}),
6364
),
6465
CFBundlePackageType: zod.literal("XFWK"),
@@ -100,13 +101,12 @@ export async function writeFrameworkInfo(
100101

101102
type LinkFrameworkOptions = {
102103
frameworkPath: string;
104+
debugSymbolsPath?: string;
103105
newLibraryName: string;
104106
};
105107

106-
export async function linkFramework({
107-
frameworkPath,
108-
newLibraryName,
109-
}: LinkFrameworkOptions) {
108+
export async function linkFramework(options: LinkFrameworkOptions) {
109+
const { frameworkPath } = options;
110110
assert.equal(
111111
process.platform,
112112
"darwin",
@@ -117,14 +117,15 @@ export async function linkFramework({
117117
`Expected framework at '${frameworkPath}'`,
118118
);
119119
if (fs.existsSync(path.join(frameworkPath, "Versions"))) {
120-
await linkVersionedFramework({ frameworkPath, newLibraryName });
120+
await linkVersionedFramework(options);
121121
} else {
122-
await linkFlatFramework({ frameworkPath, newLibraryName });
122+
await linkFlatFramework(options);
123123
}
124124
}
125125

126126
export async function linkFlatFramework({
127127
frameworkPath,
128+
debugSymbolsPath,
128129
newLibraryName,
129130
}: LinkFrameworkOptions) {
130131
assert.equal(
@@ -151,16 +152,44 @@ export async function linkFlatFramework({
151152
...frameworkInfo,
152153
CFBundleExecutable: newLibraryName,
153154
});
155+
154156
// Rename the actual binary
155157
await fs.promises.rename(
156158
path.join(frameworkPath, frameworkInfo.CFBundleExecutable),
157159
path.join(frameworkPath, newLibraryName),
158160
);
159161
// Rename the framework directory
160-
await fs.promises.rename(
161-
frameworkPath,
162-
path.join(path.dirname(frameworkPath), `${newLibraryName}.framework`),
162+
const newFrameworkPath = path.join(
163+
path.dirname(frameworkPath),
164+
`${newLibraryName}.framework`,
163165
);
166+
await fs.promises.rename(frameworkPath, newFrameworkPath);
167+
168+
if (debugSymbolsPath) {
169+
const frameworkDebugSymbolsPath = path.join(
170+
debugSymbolsPath,
171+
`${path.basename(frameworkPath)}.dSYM`,
172+
);
173+
if (fs.existsSync(frameworkDebugSymbolsPath)) {
174+
// Remove existing DWARF data
175+
await fs.promises.rm(frameworkDebugSymbolsPath, {
176+
recursive: true,
177+
force: true,
178+
});
179+
// Rebuild DWARF data
180+
await spawn(
181+
"dsymutil",
182+
[
183+
path.join(newFrameworkPath, newLibraryName),
184+
"-o",
185+
path.join(debugSymbolsPath, newLibraryName + ".dSYM"),
186+
],
187+
{
188+
outputMode: "buffered",
189+
},
190+
);
191+
}
192+
}
164193
}
165194

166195
export async function linkVersionedFramework({
@@ -282,7 +311,17 @@ export async function linkXcframework({
282311
framework.LibraryIdentifier,
283312
framework.LibraryPath,
284313
);
285-
await linkFramework({ frameworkPath, newLibraryName });
314+
await linkFramework({
315+
frameworkPath,
316+
newLibraryName,
317+
debugSymbolsPath: framework.DebugSymbolsPath
318+
? path.join(
319+
outputPath,
320+
framework.LibraryIdentifier,
321+
framework.DebugSymbolsPath,
322+
)
323+
: undefined,
324+
});
286325
}),
287326
);
288327

0 commit comments

Comments
 (0)