Skip to content

Commit 4cf619b

Browse files
committed
Add support for linux and macos binaries
1 parent 8f65af2 commit 4cf619b

File tree

2 files changed

+178
-98
lines changed

2 files changed

+178
-98
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ installer/clidriver
99
.blackduck
1010
.synopsys
1111
.vs
12+
.vscode
13+
ibmdb-binaries
14+

installer/driverInstall.js

Lines changed: 175 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,11 @@ var install_node_ibm_db = function(file_url) {
542542
else
543543
{
544544
var buildString = buildString + " --IBM_DB_HOME=\"$IBM_DB_HOME\"";
545+
var nodever = parseInt(process.versions.node.split('.')[0], 10);
545546
var childProcess = exec(buildString, function (error, stdout, stderr) {
546547
if( downloadProgress == 0 ) printMsg(stdout);
547548
if (error !== null) {
548-
if (vscode_build &&
549+
if ((vscode_build || nodever > 15) &&
549550
(platform == 'darwin' || platform == 'linux')) {
550551
// "node-gyp" FAILED: RUN Pre-compiled Binary Installation.
551552
if(!downloadProgress) {
@@ -611,114 +612,184 @@ var install_node_ibm_db = function(file_url) {
611612

612613
function installPreCompiledBinary()
613614
{
614-
if(platform == 'win32' || vscode_build) {
615-
if(arch.indexOf("64") > 0) {
616-
var BUILD_FILE = path.resolve(CURRENT_DIR, 'build.zip');
617-
var odbcBindingsNode;
618-
var fileName;
619-
var ODBC_BINDINGS = 'build\/Release\/odbc_bindings.node';
620-
621-
if(vscode_build)
622-
{
623-
var electronVersion = (electron_version).split('.');
624-
if (platform == 'darwin') {
625-
if (arch == 'arm64') {
626-
fileName = "_macarm_" + electronVersion[0];
627-
} else {
628-
fileName = "_mac_" + electronVersion[0];
629-
}
630-
} else if (platform == 'win32') {
631-
fileName = "_win_" + electronVersion[0];
632-
} else {
633-
fileName = "_linux_" + electronVersion[0];
634-
}
635-
odbcBindingsNode = 'build\/Release\/odbc_bindings' + fileName + '.node';
636-
if(electronVersion[0] < 22) {
637-
console.log("No precompiled electron binary available"+
638-
" for electron " + electron_version + "\n");
639-
process.exit(1);
640-
}
641-
}
642-
else
643-
{
644-
//Windows node binary names should update here.
645-
var ODBC_BINDINGS_V14 = 'build\/Release\/odbc_bindings.node.14.21.3';
646-
var ODBC_BINDINGS_V15 = 'build\/Release\/odbc_bindings.node.15.14.0';
647-
var ODBC_BINDINGS_V16 = 'build\/Release\/odbc_bindings.node.16.20.2';
648-
var ODBC_BINDINGS_V17 = 'build\/Release\/odbc_bindings.node.17.9.1';
649-
var ODBC_BINDINGS_V18 = 'build\/Release\/odbc_bindings.node.18.20.8';
650-
var ODBC_BINDINGS_V19 = 'build\/Release\/odbc_bindings.node.19.9.0';
651-
var ODBC_BINDINGS_V20 = 'build\/Release\/odbc_bindings.node.20.19.2';
652-
var ODBC_BINDINGS_V21 = 'build\/Release\/odbc_bindings.node.21.7.3';
653-
var ODBC_BINDINGS_V22 = 'build\/Release\/odbc_bindings.node.22.16.0';
654-
var ODBC_BINDINGS_V23 = 'build\/Release\/odbc_bindings.node.23.11.1';
655-
656-
// Windows add-on binary for node.js v0.10.x, v0.12.7, 4.x, 6.x to 14.x has been discontinued.
657-
if(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 14.0) {
658-
console.log('\nERROR: Did not find precompiled add-on binary for node.js version ' + process.version + ':' +
659-
'\nibm_db does not provide precompiled add-on binary for node.js version ' + process.version +
660-
' on Windows platform. Visual Studio is required to compile ibm_db with node.js versions < 14.X. ' +
661-
'Otherwise please use the node.js version >= 14.X\n');
662-
process.exit(1);
663-
}
615+
if(arch.indexOf("32") > 0) {
616+
console.log('32 bit platform is not supported. Please ' +
617+
'install 64 bit NodeJS on 64 bit OS for ibm_db.\n');
618+
process.exit(1);
619+
} else if(arch.indexOf("ppc") > 0 || arch.indexOf("s390") > 0) {
620+
console.log('There is no precompiled binary for platform = ' +
621+
platform + ', architecture = ' + arch + '\n');
664622

665-
/*
666-
* odbcBindingsNode will consist of the node binary-
667-
* file name according to the node version in the system.
668-
*/
669-
odbcBindingsNode =
670-
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 15.0) && ODBC_BINDINGS_V14 ||
671-
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 16.0) && ODBC_BINDINGS_V15 ||
672-
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 17.0) && ODBC_BINDINGS_V16 ||
673-
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 18.0) && ODBC_BINDINGS_V17 ||
674-
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 19.0) && ODBC_BINDINGS_V18 ||
675-
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 20.0) && ODBC_BINDINGS_V19 ||
676-
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 21.0) && ODBC_BINDINGS_V20 ||
677-
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 22.0) && ODBC_BINDINGS_V21 ||
678-
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 23.0) && ODBC_BINDINGS_V22 ||
679-
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 23.0) && ODBC_BINDINGS_V23 ||
680-
ODBC_BINDINGS;
681-
}
682-
// We have correct bindings file in odbcBindingsNode for
683-
// installed node version now. Extract it from build.zip file.
684-
printMsg("Extracting " + odbcBindingsNode + " from build.zip");
623+
} else if(platform == 'win32' || vscode_build) {
624+
var BUILD_FILE = path.resolve(CURRENT_DIR, 'build.zip');
625+
var odbcBindingsNode;
626+
var fileName;
627+
var ODBC_BINDINGS = 'build\/Release\/odbc_bindings.node';
685628

686-
// Removing the "build" directory created by Auto Installation Process.
687-
// "adm-zip" will create a fresh "build" directory for extraction of "build.zip".
688-
removeDir('build');
689-
var zip = new AdmZip(BUILD_FILE);
629+
if(vscode_build)
630+
{
631+
var electronVersion = (electron_version).split('.');
632+
if (platform == 'darwin') {
633+
if (arch == 'arm64') {
634+
fileName = "_macarm_" + electronVersion[0];
635+
} else {
636+
fileName = "_mac_" + electronVersion[0];
637+
}
638+
} else if (platform == 'win32') {
639+
fileName = "_win_" + electronVersion[0];
640+
} else {
641+
fileName = "_linux_" + electronVersion[0];
642+
}
643+
odbcBindingsNode = 'build\/Release\/odbc_bindings' + fileName + '.node';
644+
if(electronVersion[0] < 22) {
645+
console.log("No precompiled electron binary available"+
646+
" for electron " + electron_version + "\n");
647+
process.exit(1);
648+
}
649+
}
650+
else
651+
{
652+
//Windows node binary names should update here.
653+
var ODBC_BINDINGS_V14 = 'build\/Release\/odbc_bindings.node.14.21.3';
654+
var ODBC_BINDINGS_V15 = 'build\/Release\/odbc_bindings.node.15.14.0';
655+
var ODBC_BINDINGS_V16 = 'build\/Release\/odbc_bindings.node.16.20.2';
656+
var ODBC_BINDINGS_V17 = 'build\/Release\/odbc_bindings.node.17.9.1';
657+
var ODBC_BINDINGS_V18 = 'build\/Release\/odbc_bindings.node.18.20.8';
658+
var ODBC_BINDINGS_V19 = 'build\/Release\/odbc_bindings.node.19.9.0';
659+
var ODBC_BINDINGS_V20 = 'build\/Release\/odbc_bindings.node.20.19.2';
660+
var ODBC_BINDINGS_V21 = 'build\/Release\/odbc_bindings.node.21.7.3';
661+
var ODBC_BINDINGS_V22 = 'build\/Release\/odbc_bindings.node.22.16.0';
662+
var ODBC_BINDINGS_V23 = 'build\/Release\/odbc_bindings.node.23.11.1';
663+
664+
// Windows add-on binary for node.js v0.10.x, v0.12.7, 4.x, 6.x to 14.x has been discontinued.
665+
if(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 14.0) {
666+
console.log('\nERROR: Did not find precompiled add-on binary for node.js version ' + process.version + ':' +
667+
'\nibm_db does not provide precompiled add-on binary for node.js version ' + process.version +
668+
' on Windows platform. Visual Studio is required to compile ibm_db with node.js versions < 14.X. ' +
669+
'Otherwise please use the node.js version >= 14.X\n');
670+
process.exit(1);
671+
}
690672

691673
/*
692-
* adm-zip will parse the build.zip file content and
693-
* then it will check for the odbcBindingsNode
694-
* (node Binary), when it gets that binary file,
695-
* zip.extractEntryTo will write the same node binary
696-
* but the name will be odbc_bindings.node, and the other
697-
* binary files and build.zip will be discarded.
674+
* odbcBindingsNode will consist of the node binary-
675+
* file name according to the node version in the system.
698676
*/
699-
zip.forEach(function(entry) {
700-
if (entry.entryName === odbcBindingsNode) {
701-
try {
702-
zip.extractEntryTo(entry, CURRENT_DIR, true, false, false, ODBC_BINDINGS);
703-
} catch (e) {
704-
console.log('Installation Failed! \n',e);
705-
process.exit(1);
706-
}
677+
odbcBindingsNode =
678+
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 15.0) && ODBC_BINDINGS_V14 ||
679+
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 16.0) && ODBC_BINDINGS_V15 ||
680+
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 17.0) && ODBC_BINDINGS_V16 ||
681+
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 18.0) && ODBC_BINDINGS_V17 ||
682+
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 19.0) && ODBC_BINDINGS_V18 ||
683+
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 20.0) && ODBC_BINDINGS_V19 ||
684+
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 21.0) && ODBC_BINDINGS_V20 ||
685+
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 22.0) && ODBC_BINDINGS_V21 ||
686+
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 23.0) && ODBC_BINDINGS_V22 ||
687+
(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 24.0) && ODBC_BINDINGS_V23 ||
688+
ODBC_BINDINGS;
689+
}
690+
// We have correct bindings file in odbcBindingsNode for
691+
// installed node version now. Extract it from build.zip file.
692+
printMsg("Extracting " + odbcBindingsNode + " from build.zip");
707693

708-
printMsg("\n" +
709-
"===================================\n"+
710-
"ibm_db installed successfully.\n"+
711-
"===================================\n");
694+
// Removing the "build" directory created by Auto Installation Process.
695+
// "adm-zip" will create a fresh "build" directory for extraction of "build.zip".
696+
removeDir('build');
697+
var zip = new AdmZip(BUILD_FILE);
698+
699+
/*
700+
* adm-zip will parse the build.zip file content and
701+
* then it will check for the odbcBindingsNode
702+
* (node Binary), when it gets that binary file,
703+
* zip.extractEntryTo will write the same node binary
704+
* but the name will be odbc_bindings.node, and the other
705+
* binary files and build.zip will be discarded.
706+
*/
707+
zip.forEach(function(entry) {
708+
if (entry.entryName === odbcBindingsNode) {
709+
try {
710+
zip.extractEntryTo(entry, CURRENT_DIR, true, false, false, ODBC_BINDINGS);
711+
} catch (e) {
712+
installationFailed(e);
712713
}
713-
});
714714

715-
return 1;
715+
printMsg("\n" +
716+
"===================================\n"+
717+
"ibm_db installed successfully.\n"+
718+
"===================================\n");
719+
}
720+
});
716721

722+
return 1;
723+
} else if(platform == 'linux' || platform == 'darwin') {
724+
// let binaryUrl = 'https://github.com/ibmdb/ibmdb-binaries/raw/refs/heads/main/odbc_bindings';
725+
let binaryUrl = 'https://raw.githubusercontent.com/ibmdb/ibmdb-binaries/refs/heads/main/odbc_bindings';
726+
let osName;
727+
const nodeVersion = process.versions.node.split('.')[0];
728+
const ODBC_BINDINGS = 'build\/Release\/odbc_bindings.node';
729+
const outputFile = path.resolve(CURRENT_DIR, ODBC_BINDINGS);
730+
731+
if (platform == 'darwin') {
732+
if (arch == 'arm64') {
733+
osName = "_macarm";
734+
} else {
735+
osName = "_mac";
736+
}
717737
} else {
718-
console.log('32 bit platform is not supported. Please ' +
719-
'install 64 bit NodeJS on 64 bit OS for ibm_db.\n');
720-
process.exit(1);
738+
osName = "_linux";
721739
}
740+
binaryUrl = binaryUrl + osName + '.node.' + nodeVersion;
741+
742+
// Parse URL to use with https.request
743+
const { hostname, pathname } = new URL(binaryUrl);
744+
745+
const options = {
746+
hostname,
747+
path: pathname,
748+
method: 'GET',
749+
agent: httpsAgent,
750+
headers: {
751+
'User-Agent': 'Node.js HTTPS Client'
752+
}
753+
};
754+
755+
const req = https.request(options, (res) => {
756+
if (res.statusCode !== 200) {
757+
console.error(`Download failed: HTTP ${res.statusCode}`);
758+
res.resume();
759+
installationFailed();
760+
}
761+
762+
const total_bytes = parseInt(res.headers['content-length'], 10);
763+
const outStream = fs.createWriteStream(outputFile);
764+
let received_bytes = 0;
765+
766+
res.on('data', (chunk) => {
767+
received_bytes += chunk.length;
768+
showDownloadingProgress(received_bytes, total_bytes);
769+
});
770+
771+
res.pipe(outStream);
772+
773+
outStream.on('finish', () => {
774+
printMsg('\n✅ Download complete:' + outputFile);
775+
printMsg("\n" +
776+
"===================================\n"+
777+
"ibm_db installed successfully.\n"+
778+
"===================================\n");
779+
});
780+
781+
outStream.on('error', (err) => {
782+
console.error('\n❌ File write error:', err.message);
783+
installationFailed();
784+
});
785+
});
786+
787+
req.on('error', (err) => {
788+
console.error('\n❌ HTTPS request error:', err.message);
789+
installationFailed();
790+
});
791+
792+
req.end();
722793
}
723794
}
724795

@@ -832,6 +903,12 @@ function printMakeVersion() {
832903
}
833904
}
834905

906+
function installationFailed(msg) {
907+
console.log('Installation Failed!');
908+
if (msg) console.log(msg);
909+
process.exit(1);
910+
}
911+
835912
/* Detect electron version to compile ibm_db by checking version of installed
836913
electron package, or version of installed VSCode in the system.
837914
*/

0 commit comments

Comments
 (0)