Download prebuilt binary files at npm install time (#906)

Download prebuilt binary files at `npm install` time

issue #904
This commit is contained in:
Simon Edwards 2022-01-01 19:18:45 +01:00 committed by GitHub
parent 01d3c03fb2
commit 26736d06c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 3071 additions and 2974 deletions

View File

@ -254,6 +254,21 @@ if (WIN32)
endif()
if (LINUX)
# Set the RPATH in the binary to a relative one to allow it to find our Qt
# libraries regardless of where the base installation directory is.
file(RELATIVE_PATH QT_LIBRARY_REL_PATH "${CMAKE_BINARY_DIR}/Release" "${QT_CMAKE_HOME_DIR}/../..")
set_target_properties(${CORE_WIDGETS_ADDON} PROPERTIES INSTALL_RPATH "\$ORIGIN/${QT_LIBRARY_REL_PATH}")
set_target_properties(${CORE_WIDGETS_ADDON} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
endif()
if (APPLE)
file(RELATIVE_PATH QT_LIBRARY_REL_PATH "${CMAKE_BINARY_DIR}/Release" "${QT_CMAKE_HOME_DIR}/../..")
set_target_properties(${CORE_WIDGETS_ADDON} PROPERTIES INSTALL_RPATH "@loader_path/${QT_LIBRARY_REL_PATH}")
set_target_properties(${CORE_WIDGETS_ADDON} PROPERTIES SKIP_BUILD_RPATH FALSE)
set_target_properties(${CORE_WIDGETS_ADDON} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
endif()
target_link_libraries(${CORE_WIDGETS_ADDON} PRIVATE
"${CMAKE_JS_LIB}"
Qt5::Widgets

145
README.md
View File

@ -57,48 +57,16 @@ https://github.com/nodegui/examples
- Checkout the examples: https://github.com/nodegui/examples .
- [Tutorial: Build a native Meme Search Desktop app with Javascript (NodeGui) and Giphy API](https://www.sitepoint.com/build-native-desktop-gif-searcher-app-using-nodegui/)
## Installation
NodeGui requires CMake and Compilation Tools as it is a wrapper for a native C++ widget toolkit QT.
Detailed instructions here: https://www.sitepoint.com/build-native-desktop-gif-searcher-app-using-nodegui/
TL;DR:
MacOS
```
brew install cmake
brew install make
```
Windows
https://cmake.org/download/
Linux (Debian/Ubuntu)
```
sudo apt-get install pkg-config build-essential
sudo apt-get install cmake make
sudo apt-get install mesa-common-dev libglu1-mesa-dev
```
Linux (Fedora/RHEL/CentOS)
```
sudo dnf groupinstall "Development Tools" "Development Libraries"
sudo dnf groupinstall "C Development Tools and Libraries"
sudo dnf install mesa-libGL mesa-libGL-devel
```
Then install NodeGui from your command line:
#### To install latest stable release:
To install latest stable release:
```
npm install @nodegui/nodegui
```
#### To install the latest version available on master branch:
To install the latest version available on master branch:
```
npm install https://github.com/nodegui/nodegui/releases/download/v0.0.0-latest-master/nodegui-master.tgz
@ -121,7 +89,82 @@ npm install @nodegui/nodegui
See [FAQs](https://github.com/nodegui/nodegui/tree/master/website/docs/faq.md#why-does-installation-fail-at-minimal-qt-setup) for more details.
#### Using your own custom Qt installation (Optional)
## Community guides
- [Tutorial: Build a native Meme Search Desktop app with Javascript (NodeGui) and Giphy API](https://www.sitepoint.com/build-native-desktop-gif-searcher-app-using-nodegui/)
- https://blog.logrocket.com/electron-alternatives-exploring-nodegui-and-react-nodegui/ - Electron alternatives: Exploring NodeGUI and React NodeGUI by [Siegfried Grimbeek](https://blog.logrocket.com/author/siegfriedgrimbeek/).
- https://hibbard.eu/node-gui/ - Excellent guide from [James Hibbard](https://github.com/jameshibbard).
## Talks/Podcasts
- [NodeGui and React NodeGui at KarmaJS Nov 2019 meetup: https://www.youtube.com/watch?v=8jH5gaEEDv4](https://www.youtube.com/watch?v=8jH5gaEEDv4)
- <audio data-theme="night" data-src="https://changelog.com/jsparty/96/embed" src="https://cdn.changelog.com/uploads/jsparty/96/js-party-96.mp3" preload="none" class="changelog-episode" controls></audio><p><a href="https://changelog.com/jsparty/96">JS Party 96: Performant Node desktop apps with NodeGUI</a> Listen on <a href="https://changelog.com/">Changelog.com</a></p>
## Docs for contributing
```
It is easier than you think, try it
```
Looking to contribute? If you wish to implement a new widget/add more features and need help understanding the codebase, you can start here: [Contributing developer docs](https://github.com/nodegui/nodegui/tree/master/website/docs/development).
Please read https://github.com/nodegui/.github/blob/master/CONTRIBUTING.md
## Building from source
This section is useful for those wanting to work on NodeGui itself.
### Required tooling
NodeGui requires CMake and Compilation Tools as it is a wrapper for a native C++ widget toolkit QT.
Detailed instructions here: https://www.sitepoint.com/build-native-desktop-gif-searcher-app-using-nodegui/
TL;DR:
**MacOS**
```
brew install cmake
brew install make
```
**Windows**
https://cmake.org/download/
**Linux (Debian/Ubuntu)**
```
sudo apt-get install pkg-config build-essential
sudo apt-get install cmake make
sudo apt-get install mesa-common-dev libglu1-mesa-dev
```
**Linux (Fedora/RHEL/CentOS)**
```
sudo dnf groupinstall "Development Tools" "Development Libraries"
sudo dnf groupinstall "C Development Tools and Libraries"
sudo dnf install mesa-libGL mesa-libGL-devel
```
### Building
Once you have cloned this git repository, run this to build:
```
npm install
npm run build
```
The last step will takes some time to run as it builds the C++ binaries at the core of NodeGui.
### Using your own custom Qt installation (Optional)
**Compiling Qt from source**
@ -160,7 +203,7 @@ Now just `rm -rf node_modules` and do `npm install` again.
The logs should say something like `CustomQt detected at <your qt path>. Hence, skipping Mini Qt installation`.
**Running example programs**
### Running example programs
A number of small programs to show different parts of the Qt API are in `src/examples`. They can be run directly with:
@ -168,34 +211,6 @@ A number of small programs to show different parts of the Qt API are in `src/exa
npm run qode dist/examples/modelview_1_readonly.js
```
**Community guides**
- [Tutorial: Build a native Meme Search Desktop app with Javascript (NodeGui) and Giphy API](https://www.sitepoint.com/build-native-desktop-gif-searcher-app-using-nodegui/)
- https://blog.logrocket.com/electron-alternatives-exploring-nodegui-and-react-nodegui/ - Electron alternatives: Exploring NodeGUI and React NodeGUI by [Siegfried Grimbeek](https://blog.logrocket.com/author/siegfriedgrimbeek/).
- https://hibbard.eu/node-gui/ - Excellent guide from [James Hibbard](https://github.com/jameshibbard).
**Talks/Podcasts**
- [NodeGui and React NodeGui at KarmaJS Nov 2019 meetup: https://www.youtube.com/watch?v=8jH5gaEEDv4](https://www.youtube.com/watch?v=8jH5gaEEDv4)
- <audio data-theme="night" data-src="https://changelog.com/jsparty/96/embed" src="https://cdn.changelog.com/uploads/jsparty/96/js-party-96.mp3" preload="none" class="changelog-episode" controls></audio><p><a href="https://changelog.com/jsparty/96">JS Party 96: Performant Node desktop apps with NodeGUI</a> Listen on <a href="https://changelog.com/">Changelog.com</a></p>
## Docs for contributing
```
It is easier than you think, try it
```
Looking to contribute? If you wish to implement a new widget/add more features and need help understanding the codebase, you can start here: [Contributing developer docs](https://github.com/nodegui/nodegui/tree/master/website/docs/development).
Please read https://github.com/nodegui/.github/blob/master/CONTRIBUTING.md
## Building
`npm run build`
Optionally set `QT_INSTALL_DIR='/path/to/qt'` environment variable to build using your own version of Qt.
## Updating docs
`npm run docs`

View File

@ -16,8 +16,9 @@
"scripts": {
"dev": "cross-env npm run build && node ./scripts/qode.js dist/demo.js",
"build": "cross-env tsc && npm run build:addon",
"install": "cross-env npm run setupqt && (node ./scripts/skip.js || npm run build:addon)",
"install": "cross-env npm run setupqt && (node ./scripts/skip.js || npm run setupbinary || npm run build:addon)",
"setupqt": "cross-env node ./scripts/setupMiniQt.js",
"setupbinary": "cross-env node ./scripts/setupBinary.js",
"build:addon": "cross-env CMAKE_BUILD_PARALLEL_LEVEL=8 cmake-js compile",
"test": "node ./scripts/qode.js ./node_modules/jest/bin/jest -i",
"lint:cpp": "cross-env clang-format -i --glob=src/cpp/**/*.[h,c]*",
@ -40,7 +41,8 @@
"memoize-one": "^5.2.1",
"node-addon-api": "^4.0.0",
"postcss": "^7.0.17",
"postcss-nodegui-autoprefixer": "0.0.7"
"postcss-nodegui-autoprefixer": "0.0.7",
"tar": "^6.0.1"
},
"devDependencies": {
"@types/bindings": "^1.5.1",

39
scripts/setupBinary.js Normal file
View File

@ -0,0 +1,39 @@
#!/usr/bin/env node
const os = require('os');
const fs = require('fs');
const path = require('path');
const { setupArtifact } = require('@nodegui/artifact-installer');
const tar = require('tar');
const SETUP_DIR = path.resolve(__dirname, '..', 'build', 'Release');
const packageJson = require('../package');
async function setupBinary() {
const packageVersion = packageJson.version;
const tarballName = `nodegui-binary-v${packageVersion}-${os.platform()}-${os.arch()}.tar.gz`;
const url = `https://github.com/nodegui/nodegui/releases/download/v${packageVersion}/${tarballName}`;
await setupArtifact({
outDir: SETUP_DIR,
id: 'nodegui-core',
displayName: `Precompiled NodeGui binary`,
downloadLink: url,
skipSetup: () => false,
});
const tarPath = path.join(SETUP_DIR, tarballName.slice(0, -3));
tar.extract({
cwd: SETUP_DIR,
file: tarPath,
sync: true,
});
fs.unlinkSync(tarPath);
}
setupBinary()
.catch((err) => {
console.error(err);
process.exit(1);
})
.then(() => {
process.exit(0);
});

5840
yarn.lock

File diff suppressed because it is too large Load Diff