Skip to content

Commit 2f9efcf

Browse files
authored
chore(🗿): use m142 for Skia Graphite (#3615)
1 parent cb611c8 commit 2f9efcf

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

packages/skia/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"android-arm64-v8a": "6be2711ca4c31523d381420e98cabfe7e7939e246975c7b427968d5dd3b62be9",
2727
"android-x86": "888934ddc34f431c7fac5628f633dc11a4e84d68c41adb33307ae7586cc7b0b5",
2828
"android-x86_64": "2180a5be52d51bbf1dabaf95051ed0ce422b047157bcda6e486657c2c7b87ceb",
29-
"apple-xcframeworks": "cb50d9c85c9f02389ecc433912145e4a7ce2277bfe26a69dd7f7a9db74c9e276"
29+
"apple-xcframeworks": "6c9e4c565977acaf9d4f4b113050cfe8f9804602fd3cd4ec982c605fa7b040e6"
3030
}
3131
},
3232
"description": "High-performance React Native Graphics using Skia",

packages/skia/scripts/install-skia.mjs

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ console.log(
5959
`📦 Downloading Skia prebuilt binaries for ${releaseTag}`
6060
);
6161

62-
const runCommand = (command, args) => {
62+
const runCommand = (command, args, options = {}) => {
6363
return new Promise((resolve, reject) => {
6464
const child = spawn(command, args, {
6565
stdio: ["ignore", "inherit", "inherit"],
66+
...options,
6667
});
6768
child.on("error", (error) => {
6869
reject(error);
@@ -77,6 +78,75 @@ const runCommand = (command, args) => {
7778
});
7879
};
7980

81+
const runCommandWithOutput = (command, args, options = {}) => {
82+
return new Promise((resolve, reject) => {
83+
const child = spawn(command, args, {
84+
stdio: ["ignore", "pipe", "pipe"],
85+
...options,
86+
});
87+
let stdout = "";
88+
let stderr = "";
89+
child.stdout.on("data", (data) => {
90+
stdout += data.toString();
91+
});
92+
child.stderr.on("data", (data) => {
93+
stderr += data.toString();
94+
});
95+
child.on("error", (error) => {
96+
reject(error);
97+
});
98+
child.on("close", (code) => {
99+
if (code === 0) {
100+
resolve(stdout.trim());
101+
} else {
102+
reject(new Error(`Command ${command} exited with code ${code}: ${stderr}`));
103+
}
104+
});
105+
});
106+
};
107+
108+
const skiaDir = path.resolve(__dirname, "../../../externals/skia");
109+
110+
const checkoutSkiaBranch = async (version) => {
111+
const branchName = `chrome/${version}`;
112+
113+
// Check if the skia directory exists and is a git repo
114+
// (won't exist when installed via npm - submodule is not included in the package)
115+
if (!fs.existsSync(skiaDir) || !fs.existsSync(path.join(skiaDir, ".git"))) {
116+
return;
117+
}
118+
119+
console.log(`🔀 Checking out Skia branch: ${branchName}`);
120+
121+
try {
122+
// Get current branch/commit
123+
const currentRef = await runCommandWithOutput("git", ["rev-parse", "--abbrev-ref", "HEAD"], { cwd: skiaDir });
124+
125+
if (currentRef === branchName) {
126+
console.log(` ✓ Already on branch ${branchName}`);
127+
return;
128+
}
129+
130+
// Fetch the branch from origin
131+
console.log(` Fetching branch ${branchName} from origin...`);
132+
try {
133+
await runCommand("git", ["fetch", "origin", `${branchName}:${branchName}`], { cwd: skiaDir });
134+
} catch (e) {
135+
// Branch might already exist locally, try to update it
136+
await runCommand("git", ["fetch", "origin", branchName], { cwd: skiaDir });
137+
}
138+
139+
// Checkout the branch (use -f to discard local changes in the submodule)
140+
console.log(` Checking out ${branchName}...`);
141+
await runCommand("git", ["checkout", "-f", branchName], { cwd: skiaDir });
142+
143+
console.log(` ✓ Successfully checked out ${branchName}`);
144+
} catch (error) {
145+
console.error(` ⚠️ Failed to checkout branch ${branchName}: ${error.message}`);
146+
console.error(" Headers may not match the prebuilt binaries!");
147+
}
148+
};
149+
80150
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
81151

82152
const downloadToFile = (url, destPath, maxRetries = 5) => {
@@ -359,6 +429,9 @@ const clearDirectory = (directory) => {
359429
};
360430

361431
const main = async () => {
432+
// Ensure the skia submodule is on the correct branch for copying headers
433+
await checkoutSkiaBranch(skiaVersion);
434+
362435
// Check if binaries are installed and checksums match
363436
if (areBinariesInstalled() && verifyChecksums()) {
364437
console.log("✅ Prebuilt binaries already installed with matching checksums, skipping download");

0 commit comments

Comments
 (0)