-
Notifications
You must be signed in to change notification settings - Fork 850
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(macos): build universal kubo binary
- Loading branch information
Showing
4 changed files
with
135 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
diff --git a/node_modules/kubo/src/download.js b/node_modules/kubo/src/download.js | ||
index 0c04e8d..1c90cfe 100644 | ||
--- a/node_modules/kubo/src/download.js | ||
+++ b/node_modules/kubo/src/download.js | ||
@@ -236,13 +236,23 @@ async function link ({ depBin, version }) { | ||
return localBin | ||
} | ||
|
||
+/** | ||
+ * @param {object} options | ||
+ * @param {string} options.version | ||
+ * @param {string} options.platform | ||
+ * @param {string} options.arch | ||
+ * @param {string} options.installPath | ||
+ * @param {string} options.distUrl | ||
+ */ | ||
+module.exports.download = download | ||
+ | ||
/** | ||
* @param {string} [version] | ||
* @param {string} [platform] | ||
* @param {string} [arch] | ||
* @param {string} [installPath] | ||
*/ | ||
-module.exports = async (version, platform, arch, installPath) => { | ||
+module.exports.downloadAndUpdateBin = async (version, platform, arch, installPath) => { | ||
const args = cleanArguments(version, platform, arch, installPath) | ||
|
||
return link({ | ||
diff --git a/node_modules/kubo/src/index.js b/node_modules/kubo/src/index.js | ||
index 1ec6f6a..3cece54 100644 | ||
--- a/node_modules/kubo/src/index.js | ||
+++ b/node_modules/kubo/src/index.js | ||
@@ -3,6 +3,10 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
+const { download } = require('./download') | ||
+ | ||
+module.exports.download = download | ||
+ | ||
module.exports.path = function () { | ||
if (process.env.KUBO_BINARY) { | ||
return process.env.KUBO_BINARY | ||
diff --git a/node_modules/kubo/src/post-install.js b/node_modules/kubo/src/post-install.js | ||
index 0a86c03..acd8ead 100644 | ||
--- a/node_modules/kubo/src/post-install.js | ||
+++ b/node_modules/kubo/src/post-install.js | ||
@@ -2,7 +2,7 @@ | ||
|
||
const download = require('./download') | ||
|
||
-download() | ||
+downloadAndUpdateBin() | ||
.catch(err => { | ||
console.error(err) | ||
process.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const { download } = require('kubo') | ||
const path = require('path') | ||
const tmp = require('tmp') | ||
const fs = require('fs') | ||
const os = require('os') | ||
const { execSync } = require('child_process') | ||
|
||
;(async () => { | ||
if (os.platform() !== 'darwin') { | ||
// skip when we are not running on macos | ||
return | ||
} | ||
|
||
// Remove single-platform binary | ||
const ipfsBinaryPath = path.join('node_modules', 'kubo', 'bin', 'ipfs') | ||
if (fs.existsSync(ipfsBinaryPath)) { | ||
fs.unlinkSync(ipfsBinaryPath) | ||
console.log(`Removed ${ipfsBinaryPath}`) | ||
} | ||
|
||
const packageJsonPath = require.resolve(path.join('kubo', 'package.json')) | ||
const kuboVersion = `v${require(packageJsonPath).version}` | ||
|
||
const intelDir = tmp.dirSync({ prefix: 'kubo-amd64' }).name | ||
console.log(`→ Fetchng amd64 version of Kubo ${kuboVersion} to ${intelDir}`) | ||
await download({ | ||
version: kuboVersion, | ||
platform: 'darwin', | ||
arch: 'amd64', | ||
distUrl: 'https://dist.ipfs.tech', | ||
installPath: intelDir | ||
}) | ||
|
||
const armDir = tmp.dirSync({ prefix: 'kubo-arm64' }).name | ||
console.log(`→ Fetchng arm64 version of Kubo ${kuboVersion} to ${armDir}`) | ||
await download({ | ||
version: kuboVersion, | ||
platform: 'darwin', | ||
arch: 'arm64', | ||
distUrl: 'https://dist.ipfs.tech', | ||
installPath: armDir | ||
}) | ||
|
||
// merge both and save result where the binary included in DMG lives | ||
const intelBinary = `${intelDir}/kubo/ipfs` | ||
const armBinary = `${armDir}/kubo/ipfs` | ||
const lipoCommand = `lipo -create "${intelBinary}" "${armBinary}" -output "${ipfsBinaryPath}"` | ||
|
||
execSync(lipoCommand) | ||
console.log(`→ macOS lipo command executed successfully, universal Kubo binary saved at ${ipfsBinaryPath}`) | ||
})() |