Skip to content
Open
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
6 changes: 6 additions & 0 deletions .changeset/quiet-links-stay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rock-js/plugin-brownfield-ios': patch
'@rock-js/platform-apple-helpers': patch
---

Preserve relative symlinks when copying XCFrameworks during `package:ios`. `fs.cpSync` rewrote them into absolute paths on the packaging machine, so versioned framework slices (such as the Mac Catalyst slice of `hermesvm.xcframework`) shipped symlinks pointing outside the bundle, which SwiftPM refuses to extract from a binary target archive.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ function copyFile(sourcePath: string, destinationPath: string) {
// Copy an entire directory tree, overwriting existing content.
function copyDirectory(sourcePath: string, destinationPath: string) {
ensureDirectory(path.dirname(destinationPath));
fs.cpSync(sourcePath, destinationPath, { recursive: true, force: true });
fs.cpSync(sourcePath, destinationPath, {
recursive: true,
force: true,
verbatimSymlinks: true,
});
}

// Generate a minimal Info.plist for a synthesized framework wrapper.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import type * as Fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import type * as Tools from '@rock-js/tools';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

vi.unmock('node:fs');

const fs = await vi.importActual<typeof Fs>('node:fs');

vi.mock('@rock-js/tools', async (importOriginal) => ({
...(await importOriginal<typeof Tools>()),
spinner: () => ({ start: vi.fn(), stop: vi.fn() }),
}));

const { copyHermesXcframework } = await import('../copyHermesXcframework.js');

const CATALYST_FRAMEWORK =
'hermesvm.xcframework/ios-arm64_x86_64-maccatalyst/hermesvm.framework';

describe('copyHermesXcframework', () => {
let tempDir: string;

beforeEach(() => {
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'copy-hermes-test-'));
});

afterEach(() => {
fs.rmSync(tempDir, { recursive: true, force: true });
});

it('keeps relative symlinks of versioned framework slices relative', () => {
const sourceDir = path.join(tempDir, 'ios');
const destinationDir = path.join(tempDir, 'package');
const sourceFramework = path.join(
sourceDir,
'Pods/hermes-engine/destroot/Library/Frameworks/universal',
CATALYST_FRAMEWORK,
);
fs.mkdirSync(path.join(sourceFramework, 'Versions/1/Resources'), {
recursive: true,
});
fs.writeFileSync(path.join(sourceFramework, 'Versions/1/hermesvm'), '');
fs.symlinkSync('1', path.join(sourceFramework, 'Versions/Current'));
fs.symlinkSync(
'Versions/Current/hermesvm',
path.join(sourceFramework, 'hermesvm'),
);
fs.symlinkSync(
'Versions/Current/Resources',
path.join(sourceFramework, 'Resources'),
);

copyHermesXcframework({
sourceDir,
destinationDir,
reactNativeVersion: '0.82.0',
});

const copiedFramework = path.join(destinationDir, CATALYST_FRAMEWORK);
expect(
fs.readlinkSync(path.join(copiedFramework, 'Versions/Current')),
).toBe('1');
expect(fs.readlinkSync(path.join(copiedFramework, 'hermesvm'))).toBe(
'Versions/Current/hermesvm',
);
expect(fs.readlinkSync(path.join(copiedFramework, 'Resources'))).toBe(
'Versions/Current/Resources',
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function copyHermesXcframework({
`Pods/hermes-engine/destroot/Library/Frameworks/universal/${hermesFrameworkName}`,
),
hermesDestination,
{ recursive: true, force: true },
{ recursive: true, force: true, verbatimSymlinks: true },
);

loader.stop(`Copied ${color.bold(hermesFrameworkName)}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function copyReactXcframeworks({
fs.cpSync(reactFrameworkSource, reactDestination, {
recursive: true,
force: true,
verbatimSymlinks: true,
});

loader.stop(`Copied ${color.bold(react)}`);
Expand All @@ -56,6 +57,7 @@ export function copyReactXcframeworks({
fs.cpSync(reactNativeDepsSource, reactNativeDepsDestination, {
recursive: true,
force: true,
verbatimSymlinks: true,
});

loader.stop(`Copied ${color.bold(reactNativeDependencies)}`);
Expand Down