Better build fixes for libtensorflow on all 3 platforms by nkreeger · Pull Request #270 · tensorflow/tfjs-node · GitHub
Skip to content
This repository was archived by the owner on Sep 17, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 2 additions & 49 deletions binding.gyp
2 changes: 1 addition & 1 deletion integration/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"prep": "cd node_modules/@tensorflow/tfjs-node && node scripts/install.js",
"prep": "cd node_modules/@tensorflow/tfjs-node && yarn clean-deps && node scripts/install.js",
"test": "ts-node src/test.ts && tsc && node dist/test.js"
},
"dependencies": {
Expand Down
45 changes: 32 additions & 13 deletions scripts/deps-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,50 @@
const os = require('os');
const path = require('path');

let libName = 'libtensorflow';
let frameworkLibName = 'libtensorflow_framework';
// Determine constants for deps folder names and destination (build) path names.
let depsLibTensorFlowName = 'libtensorflow';
let depsLibTensorFlowFrameworkName = 'libtensorflow_framework';

let destLibTensorFlowName = depsLibTensorFlowName;
let destLibTensorFlowFrameworkName = depsLibTensorFlowFrameworkName;

if (os.platform() === 'win32') {
libName = 'tensorflow.dll';
frameworkLibName = ''; // Not supported on Windows
depsLibTensorFlowName = 'tensorflow.dll';
depsLibTensorFlowFrameworkName = ''; // Not supported on Windows

destLibTensorFlowName = depsLibTensorFlowName;
destLibTensorFlowFrameworkName = ''; // Not supported on Windows
} else if (os.platform() === 'darwin') {
libName += '.dylib';
frameworkLibName += '.dylib';
depsLibTensorFlowName += '.dylib';
depsLibTensorFlowFrameworkName += '.dylib';

destLibTensorFlowName = depsLibTensorFlowName;
destLibTensorFlowFrameworkName = depsLibTensorFlowFrameworkName;
} else if (os.platform() === 'linux') {
libName += '.so';
frameworkLibName += '.so';
// Linux has a hard-coded version number, make the destination name simpler:
depsLibTensorFlowName += '.so.1.14.0';
depsLibTensorFlowFrameworkName += '.so.1.14.0';

destLibTensorFlowName += '.so';
destLibTensorFlowFrameworkName += '.so';
} else {
throw Exception('Unsupported platform: ' + os.platform());
}

const depsPath = path.join(__dirname, '..', 'deps');
const depsLibPath = path.join(depsPath, 'lib');
const depsLibTensorFlowPath = path.join(depsLibPath, libName);
const depsLibTensorFlowFrameworkPath = path.join(depsLibPath, frameworkLibName);

const depsLibTensorFlowPath = path.join(depsLibPath, depsLibTensorFlowName);
const depsLibTensorFlowFrameworkPath =
path.join(depsLibPath, depsLibTensorFlowFrameworkName);

module.exports = {
depsPath,
depsLibPath,
depsLibTensorFlowFrameworkName,
depsLibTensorFlowFrameworkPath,
depsLibTensorFlowName,
depsLibTensorFlowPath,
depsPath,
frameworkLibName,
libName
destLibTensorFlowFrameworkName,
destLibTensorFlowName
};
42 changes: 21 additions & 21 deletions scripts/deps-stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,57 +25,57 @@ const symlink = util.promisify(fs.symlink);
const {
depsLibTensorFlowFrameworkPath,
depsLibTensorFlowPath,
frameworkLibName,
libName
destLibTensorFlowFrameworkName,
destLibTensorFlowName
} = require('./deps-constants.js');

const action = process.argv[2];
let targetDir = process.argv[3];

// This file is Windows only - the libraries must be placed in the correct
// directory to work.
if (os.platform() !== 'win32') {
throw new Exception('Dep staging is only supported on Windows');
}

// Some windows machines contain a trailing " char:
if (targetDir != undefined && targetDir.endsWith('"')) {
targetDir = targetDir.substr(0, targetDir.length - 1);
}

const destFrameworkLibPath = path.join(targetDir, frameworkLibName);
const destLibPath = path.join(targetDir, libName);
// Setup dest binary paths:
const destLibTensorFlowPath = path.join(targetDir, destLibTensorFlowName);
const destLibTensorFlowFrameworkPath =
path.join(targetDir, destLibTensorFlowFrameworkName);

/**
* Symlinks the extracted libtensorflow library to the destination path. If the
* symlink fails, a copy is made.
*/
async function symlinkDepsLib() {
if (destLibPath === undefined) {
if (destLibTensorFlowPath === undefined) {
throw new Error('Destination path not supplied!');
}
try {
await symlink(
path.relative(path.dirname(destLibPath), depsLibTensorFlowPath),
destLibPath);
if (os.platform() !== 'win32') {
await symlink(
path.relative(
path.dirname(destFrameworkLibPath),
depsLibTensorFlowFrameworkPath),
destFrameworkLibPath);
}
path.dirname(destLibTensorFlowPath), depsLibTensorFlowPath),
destLibTensorFlowPath);
} catch (e) {
console.error(
` * Symlink of ${destLibPath} failed, creating a copy on disk.`);
await copy(depsLibTensorFlowPath, destLibPath);
if (os.platform() !== 'win32') {
await copy(depsLibTensorFlowFrameworkPath, destFrameworkLibPath);
}
console.error(` * Symlink of ${
destLibTensorFlowPath} failed, creating a copy on disk.`);
await copy(depsLibTensorFlowPath, destLibTensorFlowPath);
}
}

/**
* Moves the deps library path to the destination path.
*/
async function moveDepsLib() {
await rename(depsLibTensorFlowPath, destLibPath);
await rename(depsLibTensorFlowPath, destLibTensorFlowPath);
if (os.platform() !== 'win32') {
await rename(depsLibTensorFlowFrameworkPath, destFrameworkLibPath);
await rename(
depsLibTensorFlowFrameworkPath, destLibTensorFlowFrameworkPath);
}
}

Expand Down
32 changes: 0 additions & 32 deletions scripts/generate_defs.js

This file was deleted.

1 change: 0 additions & 1 deletion scripts/install.js