git ssb

38+

cel / git-ssb



Commit 73bf575901a7d56a23cbffa4ddf35aa2c9814156

Build and compress executables with pkg

cel committed on 12/31/2019, 12:21:50 AM
Parent: c6af1255614edad2eb11c34162f437d9e2be31c1

Files changed

bin/git-ssbchanged
build.jschanged
package.jsonchanged
.gitignoreadded
bin/git-ssbView
@@ -1,12 +1,12 @@
11 #!/usr/bin/env node
22
3-// Install sodium-native prebuild
4-if (process.env.SODIUM_NATIVE_PREBUILD == null) {
3 +// Install sodium-native prebuild if in pkg's environment
4 +var isInPkg = __dirname.startsWith('/snapshot/')
5 +if (isInPkg && process.env.SODIUM_NATIVE_PREBUILD == null) {
56 var fs = require('fs')
67 var os = require('os')
78 var path = require('path')
8- var mkdirp = require('mkdirp')
99 var home = os.homedir()
1010 var pkgJson = require('../package')
1111 var sodiumDir = path.join(home, '.local', 'lib', 'sodium-native')
1212 // Copy sodium-native prebuild and libsodium shared library into local dir.
@@ -25,13 +25,14 @@
2525 try {
2626 fs.accessSync(libsodiumFile)
2727 fs.accessSync(sodiumNativeFile)
2828 } catch(e) {
29 + var mkdirp = require('mkdirp')
2930 mkdirp.sync(archDir)
3031 fs.writeFileSync(libsodiumFile,
31- fs.readFileSync(path.join(__dirname, '../libsodium.so')))
32 + fs.readFileSync(path.join(__dirname, '../dist/libsodium.so')))
3233 fs.writeFileSync(sodiumNativeFile,
33- fs.readFileSync(path.join(__dirname, '../sodium.foolpkg')))
34 + fs.readFileSync(path.join(__dirname, '../dist/sodium.node.bin')))
3435 }
3536 }
3637
3738 var u = require('../lib/util')
build.jsView
@@ -1,24 +1,48 @@
11 var os = require('os')
22 var proc = require('child_process')
33 var path = require('path')
44 var fs = require('fs')
5 +var mkdirp = require('mkdirp')
56 var pkgJson = require('./package')
67
78 var arch = os.arch()
89 var platform = os.platform()
910 var abi = process.versions.modules
1011
11-var prebuildsDir = path.join(__dirname,
12- 'node_modules/sodium-native/prebuilds/' + platform + '-' + arch)
13-fs.writeFileSync(path.join(__dirname, 'libsodium.so'),
14- fs.readFileSync(path.join(prebuildsDir, 'libsodium.so.' + pkgJson.libsodiumVersion)))
15-fs.writeFileSync(path.join(__dirname, 'sodium.foolpkg'),
16- fs.readFileSync(path.join(prebuildsDir, 'node.abi' + abi + '.node')))
12 +process.chdir(__dirname)
13 +mkdirp.sync('dist')
1714
18-proc.spawn('pkg', [
19- path.join(__dirname, 'bin/git-ssb'),
15 +function cp(src, dest) {
16 + proc.execFileSync('/bin/cp', ['-v', src, dest], {'stdio': 'inherit'})
17 +}
18 +
19 +var prebuildsDir = 'node_modules/sodium-native/prebuilds/' + platform + '-' + arch
20 +console.log('Copying binaries...')
21 +cp(path.join(prebuildsDir, 'libsodium.so.' + pkgJson.libsodiumVersion),
22 + 'dist/libsodium.so')
23 +// pkg doesn't bundle files with .node extension
24 +cp(path.join(prebuildsDir, 'node.abi' + abi + '.node'),
25 + 'dist/sodium.node.bin')
26 +cp('bin/git-remote-ssb', 'dist/')
27 +
28 +console.log('Building pkg executable...')
29 +var pkg = proc.spawnSync('pkg', [
30 + 'bin/git-ssb',
2031 '-c', 'package.json',
2132 '--public',
22- '-t', 'node10.15.3-linux-arm64',
23- '-o', 'git-ssb'
33 + '-t', 'node' + pkgJson.nodeVersion + '-' + platform + '-' + arch,
34 + '-o', 'dist/git-ssb'
2435 ], {stdio: 'inherit'})
36 +if (pkg.status) process.exit(1)
37 +
38 +process.chdir('dist')
39 +console.log('Compressing...')
40 +var tarFile = 'git-ssb-' + pkgJson.version + '-' + platform + '-' + arch + '.tgz'
41 +proc.spawnSync('tar', [
42 + '-czvf',
43 + tarFile,
44 + 'git-remote-ssb',
45 + 'git-ssb'
46 +], {stdio: 'inherit'})
47 +
48 +console.log('Built:', tarFile)
package.jsonView
@@ -9,16 +9,20 @@
99 "main": "bin.js",
1010 "pkg": {
1111 "scripts": "lib/*.js",
1212 "assets": [
13- "libsodium.so",
14- "sodium.foolpkg"
13 + "dist/libsodium.so",
14 + "dist/sodium.node.bin",
15 + "node_modules/git-ssb-web/static/*",
16 + "node_modules/git-ssb-web/locales/*.json",
17 + "node_modules/emoji-named-characters/pngs/*.png"
1518 ]
1619 },
1720 "scripts": {
1821 "build": "node build.js"
1922 },
2023 "libsodiumVersion": "23",
24 + "nodeVersion": "10.15.3",
2125 "dependencies": {
2226 "git-remote-ssb": "^2.1.1",
2327 "git-ssb-web": "^2.11.4",
2428 "mkdirp": "^0.5.1",
@@ -36,8 +40,9 @@
3640 "ssb-mentions": "^0.4.1",
3741 "ssb-msg-schemas": "^6.3.0",
3842 "ssb-pull-requests": "^1.0.0",
3943 "ssb-ref": "^2.11.1",
44 + "sodium-native": "^2.4.6",
4045 "stream-to-pull-stream": "^1.7.2"
4146 },
4247 "devDependencies": {
4348 "pkg": "*"
.gitignoreView
@@ -1,0 +1,1 @@
1 +dist

Built with git-ssb-web