Skip to content

Commit

Permalink
feat: Add support for build-from-source argument
Browse files Browse the repository at this point in the history
  • Loading branch information
gribnoysup committed Jun 3, 2023
1 parent 82da9d9 commit 1ac2e4a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ Options:
-b, --debug Build debug version of modules
--prebuild-tag-prefix GitHub tag prefix passed to prebuild-install.
Default is "v"
--force-build-from-source Skip prebuild download and rebuild module from
source. Default is false
Copyright 2016
```
Expand Down
2 changes: 2 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const argv = yargs(process.argv.slice(2)).version(false).options({
sequential: { alias: 's', type: 'boolean', description: 'Rebuild modules sequentially, this is enabled by default on Windows' },
debug: { alias: 'b', type: 'boolean', description: 'Build debug version of modules' },
'prebuild-tag-prefix': { type: 'string', description: 'GitHub tag prefix passed to prebuild-install. Default is "v"' },
'force-build-from-source': { type: 'boolean', description: 'Skip prebuild download and rebuild module from source. Default is false' },
'force-abi': { type: 'number', description: 'Override the ABI version for the version of Electron you are targeting. Only use when targeting Nightly releases.' },
'use-electron-clang': { type: 'boolean', description: 'Use the clang executable that Electron used when building its binary. This will guarantee compiler compatibility' },
'disable-pre-gyp-copy': { type: 'boolean', description: 'Disables the pre-gyp copy step' },
Expand Down Expand Up @@ -124,6 +125,7 @@ process.on('unhandledRejection', handler);
mode: argv.p ? 'parallel' : (argv.s ? 'sequential' : undefined),
debug: argv.debug,
prebuildTagPrefix: (argv.prebuildTagPrefix as string) || 'v',
forceBuildFromSource: argv.forceBuildFromSource || false,
forceABI: argv.forceAbi as number,
useElectronClang: !!argv.useElectronClang,
disablePreGypCopy: !!argv.disablePreGypCopy,
Expand Down
21 changes: 13 additions & 8 deletions src/module-type/prebuild-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,25 @@ export class PrebuildInstall extends NativeModule {
async run(prebuildInstallPath: string): Promise<void> {
await spawn(
process.execPath,
[
path.resolve(__dirname, '..', `prebuild-shim.js`),
prebuildInstallPath,
`--arch=${this.rebuilder.arch}`,
`--platform=${this.rebuilder.platform}`,
`--tag-prefix=${this.rebuilder.prebuildTagPrefix}`,
...await this.getPrebuildInstallRuntimeArgs(),
],
await this.getPrebuildInstallArgs(prebuildInstallPath),
{
cwd: this.modulePath,
}
);
}

async getPrebuildInstallArgs(prebuildInstallPath: string): Promise<string[]> {
return [
path.resolve(__dirname, '..', `prebuild-shim.js`),
prebuildInstallPath,
`--arch=${this.rebuilder.arch}`,
`--platform=${this.rebuilder.platform}`,
`--tag-prefix=${this.rebuilder.prebuildTagPrefix}`,
this.rebuilder.forceBuildFromSource ? `--build-from-source` : '',
...(await this.getPrebuildInstallRuntimeArgs()),
].filter(Boolean);
}

async findPrebuiltModule(): Promise<boolean> {
const prebuildInstallPath = await this.locateBinary();
if (prebuildInstallPath) {
Expand Down
3 changes: 3 additions & 0 deletions src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface RebuildOptions {
useElectronClang?: boolean;
cachePath?: string;
prebuildTagPrefix?: string;
forceBuildFromSource?: boolean;
projectRootPath?: string;
forceABI?: number;
disablePreGypCopy?: boolean;
Expand Down Expand Up @@ -57,6 +58,7 @@ export class Rebuilder implements IRebuilder {
public useCache: boolean;
public cachePath: string;
public prebuildTagPrefix: string;
public forceBuildFromSource: boolean;
public msvsVersion?: string;
public useElectronClang: boolean;
public disablePreGypCopy: boolean;
Expand All @@ -74,6 +76,7 @@ export class Rebuilder implements IRebuilder {
this.useElectronClang = options.useElectronClang || false;
this.cachePath = options.cachePath || path.resolve(os.homedir(), '.electron-rebuild-cache');
this.prebuildTagPrefix = options.prebuildTagPrefix || 'v';
this.forceBuildFromSource = options.forceBuildFromSource || false;
this.msvsVersion = process.env.GYP_MSVS_VERSION;
this.disablePreGypCopy = options.disablePreGypCopy || false;

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface IRebuilder {
msvsVersion?: string;
platform: string;
prebuildTagPrefix: string;
forceBuildFromSource: boolean;
useCache: boolean;
useElectronClang: boolean;
}
12 changes: 12 additions & 0 deletions test/module-type-prebuild-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ describe('prebuild-install', () => {
])
});

it('should pass --build-from-source to prebuild-install when forceBuildFromSource is true', async () => {
const rebuilder = new Rebuilder({
...rebuilderArgs,
forceBuildFromSource: true,
});
const prebuildInstall = new PrebuildInstall(rebuilder, modulePath);
console.log(await prebuildInstall.getPrebuildInstallArgs('prebuild-install-path'))
expect(
await prebuildInstall.getPrebuildInstallArgs('prebuild-install-path')
).to.include('--build-from-source');
});

it('should not fail running prebuild-install', async () => {
const rebuilder = new Rebuilder(rebuilderArgs);
const prebuildInstall = new PrebuildInstall(rebuilder, modulePath);
Expand Down

0 comments on commit 1ac2e4a

Please sign in to comment.