Skip to content

Commit ce791b5

Browse files
committed
fix(ios): seed $(inherited) only when no other linker flags remain
Matches addToOtherLinkerFlags, which seeds it only when OTHER_LDFLAGS is unset, so a host that deliberately leaves $(inherited) out keeps it out.
1 parent 4808af7 commit ce791b5

3 files changed

Lines changed: 23 additions & 34 deletions

File tree

‎lib/services/ios-project-service.ts‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -794,10 +794,6 @@ export class IOSProjectService
794794
this.$options.hostProjectPath,
795795
buildFolderPath,
796796
);
797-
// Set the directive rather than append it: an embed forces a prepare
798-
// on every run, so appending left one more copy in OTHER_LDFLAGS per
799-
// run, and the linker concatenates the referenced files, adding a
800-
// full metadata file to the host executable each time.
801797
setMetadataSectionFlag(
802798
project,
803799
metadataSectionFlag(`${metadataPath}/metadata-arm64.bin`),
@@ -834,9 +830,6 @@ export class IOSProjectService
834830

835831
this.savePbxProj(project, projectData);
836832
} catch (err) {
837-
// A failure here leaves the host project partially set up — the
838-
// NativeScript group may exist without its linker flag. Trace-only
839-
// logging hid that, so surface it as an error.
840833
this.$logger.error(
841834
`Error adding the NativeScript group to the host project ${this.$options.hostProjectPath}. The host project may be left partially configured.`,
842835
err,

‎lib/services/ios/embed-metadata-linker-flag.ts‎

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
/**
2-
* Keeps the host project's `-sectcreate __DATA __TNSMetadata` linker flag in a
3-
* sane state when a project is prepared for embedding.
4-
*
5-
* `ns embed ios` forces a prepare on every run, and `addToOtherLinkerFlags`
6-
* appends unconditionally — so every run added another copy of the directive,
7-
* and `ld` concatenates the referenced files, growing the host executable by a
8-
* full metadata copy (roughly 9–12 MB) per run. The runtime only reads from the
9-
* start of the section, which is why the extra copies went unnoticed.
10-
*
11-
* The flag therefore has to be set, not appended: drop every existing metadata
12-
* directive (stale ones naming another architecture or path, plus duplicates
13-
* left by earlier runs), keep all other linker flags intact, and append the
14-
* wanted directive once.
2+
* `ld` accepts a repeated `-sectcreate` for the same section and concatenates
3+
* the files, so the metadata directive must be set, never appended: each extra
4+
* copy adds a full metadata file to the host executable.
155
*/
166

177
/**
@@ -115,14 +105,10 @@ export function setMetadataSectionFlag(project: any, flag: string): void {
115105
}
116106
}
117107

118-
// The host's flags are usually inherited from an xcconfig file, so
119-
// `$(inherited)` has to stay in the list; `addToOtherLinkerFlags` seeds it
120-
// the same way whenever the setting is missing.
121-
const hasInherited = kept.some(
122-
(entry) => typeof entry === "string" && entry.includes(INHERITED),
123-
);
124-
if (!hasInherited) {
125-
kept.unshift(JSON.stringify(INHERITED));
108+
// Seed `$(inherited)` only when nothing else is set, as
109+
// `addToOtherLinkerFlags` does: a host that left it out did so on purpose.
110+
if (kept.length === 0) {
111+
kept.push(JSON.stringify(INHERITED));
126112
}
127113

128114
kept.push(flag);

‎test/ios-project-service.ts‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,20 @@ describe("embed metadata linker flag", () => {
16881688
}
16891689
});
16901690

1691+
it("does not add $(inherited) to a host that left it out", async () => {
1692+
const unrelated = JSON.stringify("-ObjC");
1693+
const { prepare, flagsOfTarget, seedFlags } = setup();
1694+
seedFlags([unrelated]);
1695+
1696+
await prepare();
1697+
1698+
for (const flags of flagsOfTarget()) {
1699+
assert.lengthOf(metadataDirectives(flags), 1);
1700+
assert.include(flags, unrelated);
1701+
assert.notInclude(flags, '"$(inherited)"');
1702+
}
1703+
});
1704+
16911705
it("preserves repeated whitespace in unrelated flag arguments when stripping a directive", async () => {
16921706
const combined = JSON.stringify(
16931707
'-force_load "libs/My Library.a" -sectcreate __DATA __TNSMetadata "../embedHost/metadata-arm64.bin"',
@@ -1699,10 +1713,7 @@ describe("embed metadata linker flag", () => {
16991713

17001714
for (const flags of flagsOfTarget()) {
17011715
assert.lengthOf(metadataDirectives(flags), 1);
1702-
assert.include(
1703-
flags,
1704-
JSON.stringify('-force_load "libs/My Library.a"'),
1705-
);
1716+
assert.include(flags, JSON.stringify('-force_load "libs/My Library.a"'));
17061717
}
17071718
});
17081719

@@ -1726,8 +1737,7 @@ describe("embed metadata linker flag", () => {
17261737
(<any>testInjector.resolve("options")).hostProjectPath = mkdtempSync(
17271738
path.join(tmpdir(), "embedMetadataBrokenHost-"),
17281739
);
1729-
// The host project's pbxproj exists but the group cannot be added to it —
1730-
// the failure mode that used to leave a half-configured host.
1740+
// The host project's pbxproj exists but the group cannot be added to it.
17311741
testInjector.resolve("xcprojService").findXcodeProject = () =>
17321742
(<any>testInjector.resolve("options")).hostProjectPath;
17331743
(<any>iOSProjectService).createPbxProj = (): any => ({

0 commit comments

Comments
 (0)