Skip to content

Commit

Permalink
feat(rebuild): citizenfx-rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianTerhorst committed Oct 7, 2024
1 parent cb372cd commit 747f2a0
Show file tree
Hide file tree
Showing 63 changed files with 2,240 additions and 7,257 deletions.
86 changes: 0 additions & 86 deletions .circleci/config.yml

This file was deleted.

1 change: 0 additions & 1 deletion .github/CODEOWNERS

This file was deleted.

6 changes: 0 additions & 6 deletions .github/dependabot.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/add-to-project.yml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Release & Publish

on:
push:
tags:
- 'v*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false

publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .npmrc file to publish to npm
uses: actions/setup-node@v1
with:
node-version: '22.x'
registry-url: 'https://registry.npmjs.org'
- name: Install modules and build project
run: yarn install
- name: Get version from tag
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
if: startsWith(github.ref, 'refs/tags/')
- name: Adjust version number
run: npm version $VERSION --no-git-tag-version
- name: Publish to npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
26 changes: 0 additions & 26 deletions .github/workflows/semantic.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ node_modules

lib
test-dist
.idea
package-lock.json
9 changes: 0 additions & 9 deletions .releaserc.json

This file was deleted.

148 changes: 19 additions & 129 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
## Electron Rebuild
## CitizenFX Node Rebuild

[![CircleCI](https://circleci.com/gh/electron/rebuild.svg?style=svg)](https://circleci.com/gh/electron/rebuild)
[![NPM](https://img.shields.io/npm/v/@electron/rebuild.svg?style=flat)](https://npm.im/@electron/rebuild)
[![Coverage Status](https://codecov.io/gh/electron/rebuild/branch/main/graph/badge.svg)](https://codecov.io/gh/electron/rebuild)
[![NPM](https://img.shields.io/npm/v/@citizenfx/node-rebuild.svg?style=flat)](https://npm.im/@citizenfx/node-rebuild)

This executable rebuilds native Node.js modules against the version of Node.js
that your Electron project is using. This allows you to use native Node.js
modules in Electron apps without your system version of Node.js matching exactly
(which is often not the case, and sometimes not even possible).
This package is based on [electron-rebuild](https://github.com/electron/rebuild).

This executable is rebuilding the native NodeJS modules
you are using inside your FXServer resource
against the NodeJS version that is used by the FXServer.

### How does it work?

Install the package with `--save-dev`:
Install the @citizenfx/node-rebuild as a dev dependency with `--save-dev`:

```sh
npm install --save-dev @electron/rebuild
npm install --save-dev @citizenfx/node-rebuild
```

Then, whenever you install a new npm package, rerun electron-rebuild:
Then, whenever you install a new package inside your FXServer resource, rerun node-rebuild:

```sh
$(npm bin)/electron-rebuild
$(npm bin)/node-rebuild
```

Or if you're on Windows:

```sh
.\node_modules\.bin\electron-rebuild.cmd
.\node_modules\.bin\node-rebuild.cmd
```
If you have a good node-gyp config but you see an error about a missing element on Windows like `Could not load the Visual C++ component "VCBuild.exe"`, try to launch electron-rebuild in an npm script:
The same works inside a script in your `package.json`:

```json
"scripts": {
"rebuild": "electron-rebuild -f -w yourmodule"
"rebuild": "node-rebuild -f"
}
```

Expand All @@ -44,123 +43,14 @@ npm run rebuild

### What are the requirements?

Node v12.13.0 or higher is required. Building native modules from source uses
Node v22.6.0 or higher is required. Building native modules from source uses
[`node-gyp`](https://github.com/nodejs/node-gyp#installation), refer to the link for its
installation/runtime requirements.

### CLI Arguments

```
Usage: electron-rebuild --version [version] --module-dir [path]
Options:
-v, --version The version of Electron to build against [string]
-f, --force Force rebuilding modules, even if we would skip
it otherwise [boolean]
-a, --arch Override the target architecture to something
other than your system's [string]
-m, --module-dir The path to the node_modules directory to rebuild
[string]
-w, --which-module A specific module to build, or comma separated
list of modules. Modules will only be rebuilt if
they also match the types of dependencies being
rebuilt (see --types). [string]
-o, --only Only build specified module, or comma separated
list of modules. All others are ignored. [string]
-e, --electron-prebuilt-dir The path to the prebuilt electron module [string]
-d, --dist-url Custom header tarball URL [string]
-t, --types The types of dependencies to rebuild. Comma
separated list of "prod", "dev" and "optional".
Default is "prod,optional" [string]
-p, --parallel Rebuild in parallel, this is enabled by default
on macOS and Linux [boolean]
-s, --sequential Rebuild modules sequentially, this is enabled by
default on Windows [boolean]
-b, --debug Build debug version of modules [boolean]
--prebuild-tag-prefix GitHub tag prefix passed to prebuild-install.
Default is "v" [string]
--force-abi Override the ABI version for the version of
Electron you are targeting. Only use when
targeting Nightly releases. [number]
--use-electron-clang Use the clang executable that Electron used when
building its binary. This will guarantee compiler
compatibility [boolean]
--disable-pre-gyp-copy Disables the pre-gyp copy step [boolean]
--build-from-source Skips prebuild download and rebuilds module from
source. [boolean]
-h, --help Show help [boolean]
```

### How can I use this with [Electron Forge](https://github.com/electron/forge)?

This package is automatically used with Electron Forge when packaging an Electron app.

### How can I integrate this into [Electron Packager](https://github.com/electron/packager)?
### What if the NodeJS version changed inside the FXServer?

electron-rebuild provides a function compatible with the [`afterCopy` hook](https://electron.github.io/packager/main/interfaces/electronpackager.options.html#aftercopy)
for Electron Packager. For example:
The node-rebuild can be manually adjusted to rebuild against the NodeJS version that is required by providing the version as a cli argument.

```javascript
import packager from '@electron/packager';
import rebuild from '@electron/rebuild';

packager({
// … other options
afterCopy: [(buildPath, electronVersion, platform, arch, callback) => {
rebuild({ buildPath, electronVersion, arch })
.then(() => callback())
.catch((error) => callback(error));
}],
// … other options
});
```

### How can I integrate this with [prebuild](https://github.com/prebuild/prebuild)?

If your module uses [prebuild](https://github.com/prebuild/prebuild) for creating prebuilt binaries,
it also uses [prebuild-install](https://github.com/prebuild/prebuild-install) to download them. If
this is the case, then `electron-rebuild` will run `prebuild-install` to download the correct
binaries from the project's GitHub Releases instead of rebuilding them.

### How can I integrate this into Grunt / Gulp / Whatever?

electron-rebuild is also a library that you can require into your app or
build process. It has a very simple API:

```javascript
import rebuild from '@electron/rebuild';

// Public: Rebuilds a node_modules directory with the given Electron version.
//
// options: Object with the following properties
// buildPath - An absolute path to your app's directory. (The directory that contains your node_modules)
// electronVersion - The version of Electron to rebuild for
// arch (optional) - Default: process.arch - The arch to rebuild for
// extraModules (optional) - Default: [] - An array of modules to rebuild as well as the detected modules
// onlyModules (optional) - Default: null - An array of modules to rebuild, ONLY these module names will be rebuilt.
// The "types" property will be ignored if this option is set.
// force (optional) - Default: false - Force a rebuild of modules regardless of their current build state
// headerURL (optional) - Default: https://www.electronjs.org/headers - The URL to download Electron header files from
// types (optional) - Default: ['prod', 'optional'] - The types of modules to rebuild
// mode (optional) - The rebuild mode, either 'sequential' or 'parallel' - Default varies per platform (probably shouldn't mess with this one)
// useElectronClang (optional) - Whether to use the clang executable that Electron used when building its binary. This will guarantee compiler compatibility

// Returns a Promise indicating whether the operation succeeded or not
```

A full build process might look something like:

```javascript
const childProcess = require('child_process');
const pathToElectron = require('electron');

rebuild({
buildPath: __dirname,
electronVersion: '1.4.12'
})
.then(() => console.info('Rebuild Successful'))
.catch((e) => {
console.error("Building modules didn't work!");
console.error(e);
});
```sh
node-rebuild --nodeVersion 22.6.0
```
Loading

0 comments on commit 747f2a0

Please sign in to comment.