neon-cli
Version:
Build and load native Rust/Neon modules.
72 lines (71 loc) • 3.63 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const crate_1 = __importDefault(require("./crate"));
const target_1 = __importDefault(require("./target"));
const build_settings_1 = __importDefault(require("./build-settings"));
const log_1 = __importDefault(require("./log"));
const child_process_1 = require("./async/child_process");
/** A Neon project and its directory tree. */
class Project {
constructor(root, options) {
let { crate, targetDirectory } = options;
this.root = root;
this.targetDirectory = targetDirectory;
this.crate = new crate_1.default(this, { subdirectory: crate });
}
static create(root, options = {}) {
return __awaiter(this, void 0, void 0, function* () {
let { crate = "native" } = options;
const { stdout } = yield (0, child_process_1.execFile)("cargo", ["metadata", "--format-version=1", "--no-deps"], {
cwd: path_1.default.join(root, crate),
});
const targetDirectory = JSON.parse(stdout).target_directory;
return new Project(root, Object.assign({ targetDirectory,
crate }, options));
});
}
build(toolchain, release, args) {
return __awaiter(this, void 0, void 0, function* () {
let target = new target_1.default(this.crate, { release: release });
let settings = build_settings_1.default.current(toolchain);
// 1. Force a rebuild if build settings have changed.
if (!target.inState(settings)) {
(0, log_1.default)("forcing rebuild for new build settings");
yield target.clean();
}
// 2. Build the dylib.
(0, log_1.default)("running cargo");
yield target.build(toolchain, settings, args);
// 3. Copy the dylib as the main addon file.
(0, log_1.default)("generating " + path_1.default.join(this.crate.subdirectory, this.crate.nodefile));
yield this.crate.finish(target.dylib);
});
}
clean() {
return __awaiter(this, void 0, void 0, function* () {
// 1. Do a `cargo clean` to delete the `target` directory.
(0, log_1.default)("cargo clean");
yield (0, child_process_1.spawn)("cargo", ["clean"], { cwd: this.crate.root, stdio: "inherit" });
// 2. Remove the main addon file.
(0, log_1.default)("remove " + path_1.default.join(this.crate.subdirectory, this.crate.nodefile));
yield this.crate.removeAddon();
// 3. Clear the artifacts file.
this.crate.resetArtifacts();
this.crate.saveArtifacts();
});
}
}
exports.default = Project;
;