Skip to content

Commit

Permalink
Added ARCH flag to build for different arch
Browse files Browse the repository at this point in the history
  • Loading branch information
JezerM committed Jan 13, 2022
1 parent 845c75e commit bc9bd0d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
22 changes: 17 additions & 5 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const ora = require("ora");

let DEST_DIR = "/";
let PREFIX = "/usr";
let ARCH = process.arch;
let INSTALL_ROOT = path.resolve(__dirname, "./build/unpacked/");
let ASAR_ROOT = path.resolve(__dirname, "./build/nody-asar/");

Expand All @@ -38,12 +39,18 @@ let argv = yargs
describe: "Prefix to install at",
default: PREFIX,
})
.option("ARCH", {
type: "string",
describe: "Architecture to build for",
default: ARCH,
})
.help("h")
.alias("h", "help")
.version(false).argv;

DEST_DIR = argv.DEST_DIR;
PREFIX = argv.PREFIX;
ARCH = argv.ARCH;

// Some global variables

Expand Down Expand Up @@ -78,14 +85,14 @@ async function compile_bindings() {
console.log("Bindings copied");

let spinner = ora({
text: `Compiling bindings with electron-rebuild...`,
text: `Compiling bindings with electron-rebuild for ${ARCH}...`,
spinner: "dots",
});
spinner.start();

await new Promise((resolve) => {
child_process.exec(
"npx electron-rebuild -m .",
`npx electron-rebuild -m . --arch ${ARCH}`,
{
cwd: "./js/bindings",
encoding: "utf-8",
Expand Down Expand Up @@ -154,7 +161,8 @@ function find_electron_binding() {
}
fs.removeSync("./build/nody-asar/node_modules/node-gtk/lib/binding/");
let bindings = fs.readdirSync("./node_modules/node-gtk/lib/binding/");
let electron_binding = bindings.find((v) => v.includes("electron"));
let re = new RegExp(`electron-.*-linux-${ARCH}`);
let electron_binding = bindings.find((v) => v.match(re));
return electron_binding;
}

Expand All @@ -165,14 +173,14 @@ async function ensure_electron_binding() {
} else {
try {
let spinner = ora({
text: `Node-gtk binding for electron not found. Compiling...`,
text: `Node-gtk binding for electron not found. Compiling for ${ARCH}...`,
spinner: "dots",
});
spinner.start();

await new Promise((resolve) => {
child_process.exec(
"npx electron-rebuild -w node-gtk --build-from-source",
`npx electron-rebuild -w node-gtk --build-from-source --arch ${ARCH}`,
{
encoding: "utf-8",
stdio: "ignore",
Expand All @@ -195,6 +203,10 @@ async function ensure_electron_binding() {
process.exit(1);
}
}
if (!electron_binding) {
console.error("Electron binding couldn't be found");
process.exit(1);
}
return electron_binding;
}

Expand Down
7 changes: 7 additions & 0 deletions make.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const yargs = require("yargs");

let DEST_DIR = "/";
let PREFIX = "/usr";
let ARCH = process.arch;
let INSTALL_ROOT = path.resolve(__dirname, "./build/unpacked/");

yargs.parserConfiguration({
Expand Down Expand Up @@ -32,12 +33,18 @@ let argv = yargs
describe: "Prefix to install at",
default: PREFIX,
})
.option("ARCH", {
type: "string",
describe: "Architecture to build for",
default: ARCH,
})
.help("h")
.alias("h", "help")
.version(false).argv;

PREFIX = argv.PREFIX;
DEST_DIR = argv.DEST_DIR;
ARCH = argv.ARCH;

async function do_install() {
const { build } = require("./build.js");
Expand Down

0 comments on commit bc9bd0d

Please sign in to comment.