Skip to content

Commit 0f13e5a

Browse files
committed
Windows: Bumb [email protected]
And simplify shell script
1 parent 43bd794 commit 0f13e5a

File tree

7 files changed

+271
-69
lines changed

7 files changed

+271
-69
lines changed

binding.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
'libraries': [
1515
'<(PRODUCT_DIR)/../../windows/lib/libzmq',
1616
'ws2_32.lib',
17+
'iphlpapi'
1718
],
1819
}],
1920
['OS=="mac" or OS=="solaris"', {

scripts/build_libzmq.sh

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
#!/bin/sh
22
set -e
33

4-
test -d zmq || mkdir zmq
4+
if [ "$1" != "" ]; then
5+
ZMQ=$1
6+
else
7+
echo "No ZMQ version given"
8+
exit 1
9+
fi
510

6-
ZMQ=4.2.0
7-
ZMQ_REPO=zeromq/libzmq
8-
9-
realpath() {
10-
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
11-
}
12-
export MAIN_DIR="$(dirname $(realpath $0))/../"
13-
export ZMQ_PREFIX=$MAIN_DIR/zmq
11+
export ZMQ_PREFIX="$(dirname $0)/../zmq"
1412
export ZMQ_SRC_DIR=zeromq-$ZMQ
1513
cd $ZMQ_PREFIX
1614

1715
export CFLAGS=-fPIC
1816
export CXXFLAGS=-fPIC
1917
export PKG_CONFIG_PATH=$ZMQ_PREFIX/lib/pkgconfig
2018

21-
test -f zeromq-$ZMQ.tar.gz || ZMQ=$ZMQ ZMQ_REPO=$ZMQ_REPO node $MAIN_DIR/scripts/download-zmq.js
2219
test -d $ZMQ_SRC_DIR || tar xzf zeromq-$ZMQ.tar.gz
2320
cd $ZMQ_SRC_DIR
2421

scripts/download-zmq.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

scripts/download.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@ var https = require('https');
22
var fs = require('fs');
33
var url = require('url');
44

5-
function writeToFile(filename, response) {
5+
function writeToFile(filename, response, callback) {
66
response.pipe(fs.createWriteStream(filename));
7+
response.on('end', callback)
78
}
89

9-
function download(fileUrl, filename) {
10+
function download(fileUrl, filename, callback) {
1011
https.get(fileUrl, function(response) {
1112
if (response.statusCode > 300 && response.statusCode < 400 && response.headers.location) {
1213
if (url.parse(response.headers.location).hostname) {
1314
https.get(response.headers.location, function(res) {
14-
writeToFile(filename, res);
15+
writeToFile(filename, res, callback);
1516
});
1617
} else {
1718
https.get(url.resolve(url.parse(fileUrl).hostname, response.headers.location), function(res) {
18-
writeToFile(filename, res);
19+
writeToFile(filename, res, callback);
1920
});
2021
}
2122
} else {
22-
writeToFile(filename, response);
23+
writeToFile(filename, response, callback);
2324
}
2425
});
2526
}

scripts/preinstall.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,49 @@ var spawn = require('child_process').spawn;
33
var path = require('path');
44
var fs = require('fs');
55

6-
if (process.platform === 'win32') {
7-
console.log('Downloading libzmq for Windows')
6+
var ZMQ = '4.2.0';
7+
8+
function buildZMQ(scriptPath) {
9+
console.log('Building libzmq for ' + process.platform)
10+
11+
var child = spawn(scriptPath, [ZMQ]);
12+
13+
child.stdout.pipe(process.stdout);
14+
child.stderr.pipe(process.stderr);
15+
child.on('error', (err) => {
16+
console.error('Failed to start child process.');
17+
});
18+
}
819

9-
var TAR_URL = 'https://github.com/nteract/libzmq-win/releases/download/v1.0.0/libzmq-' + process.arch + '.lib';
20+
if (process.platform === 'win32') {
21+
var LIB_URL = 'https://github.com/nteract/libzmq-win/releases/download/v2.0.0/libzmq-' + ZMQ + '-' + process.arch + '.lib';
1022
var DIR_NAME = path.join(__dirname, '..', 'windows', 'lib');
1123
var FILE_NAME = path.join(DIR_NAME, 'libzmq.lib');
1224

1325
if (!fs.existsSync(DIR_NAME)) {
1426
fs.mkdirSync(DIR_NAME);
1527
}
1628

17-
download(TAR_URL, FILE_NAME);
29+
if (!fs.existsSync(FILE_NAME)) {
30+
console.log('Downloading libzmq for Windows');
31+
download(LIB_URL, FILE_NAME, function() {
32+
console.log('Download finished');
33+
});
34+
}
35+
1836
} else {
19-
console.log('Building libzmq for ' + process.platform)
37+
var SCRIPT_PATH = path.join(__dirname, 'build_libzmq.sh');
38+
var TAR_URL = 'https://github.com/zeromq/libzmq/releases/download/v' + ZMQ + '/zeromq-' + ZMQ + '.tar.gz';
39+
var DIR = path.join(__dirname, '..', 'zmq');
40+
var FILE_NAME = path.join(DIR, 'zeromq-' + ZMQ + '.tar.gz');
2041

21-
var child = spawn('./scripts/build_libzmq.sh');
42+
if (!fs.existsSync(DIR)) {
43+
fs.mkdirSync(DIR);
44+
}
2245

23-
child.stdout.pipe(process.stdout);
24-
child.stderr.pipe(process.stderr);
25-
child.on('error', (err) => {
26-
console.error('Failed to start child process.');
27-
});
46+
if (fs.existsSync(FILE_NAME)) {
47+
buildZMQ(SCRIPT_PATH);
48+
} else {
49+
download(TAR_URL, FILE_NAME, function() { buildZMQ(SCRIPT_PATH); });
50+
}
2851
}

0 commit comments

Comments
 (0)