Skip to content

Commit

Permalink
dx: support building desktop on win
Browse files Browse the repository at this point in the history
  • Loading branch information
staltz committed Oct 3, 2023
1 parent 8583673 commit cb669fe
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
13 changes: 12 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ In the explanations below, we will constantly refer to "development" and "target
- If your target OS is **iOS**, only **macOS** computers are supported
- If your target OS is **Android**, only **Linux and macOS** computers are supported
- _No Windows support_ so far, unfortunately; but you can always choose to install Linux for free if you have a Windows computer
- If your target is **desktop**, **Linux and macOS** computers are supported
- If your target is **desktop**, then **Linux**, **macOS** and **Windows** computers are supported

### Development Container

Expand Down Expand Up @@ -60,6 +60,17 @@ The paragraph below is commented out because we use --no-rust for all iOS compil
️ **macOS Big Sur is not supported!** Manyverse only builds on macOS Catalina or older versions. This is because Apple made significant changes to how linking dynamic libraries work, and most non-Apple tooling (which we depend on) hasn't updated yet. For more information, read [issue 1371](https://gitlab.com/staltz/manyverse/-/issues/1371). You may have luck if you compile the backend without Rust, using `npm run build-backend-ios -- --no-rust` (read more about that some sections below). -->

### Windows specifics

If you are developing Manyverse desktop on a Windows computer, then we recommend [choco](https://chocolatey.org/) to install the required tools.

Then make sure you run the following commands to install the required tools for building Node.js native addons:

- `choco install python3`
- `choco install visualstudio2017-workload-nodebuildtools`
- `npm i -g windows-build-tools`


### Node.js

Use node (preferably exactly) **`16.17.x`** and npm `8.x`. To manage node versions easily, we recommend [nvm](https://github.com/nvm-sh/nvm) and use its deep integration feature to install and load the required node version automatically.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"prebuild-desktop-release-macos": "cd desktop && cross-env DEBUG=electron-builder electron-builder install-app-deps --platform=darwin",
"build-desktop-release-macos": "electron-builder build --config desktop/electron-builder.config.js --macos --publish $EB_PUBLISH",
"clean-desktop-prebuilds": "rimraf ./desktop/node_modules/**/{bufferutil,sodium-native,leveldown,utf-8-validate}/{build,prebuilds}",
"desktop": "cd desktop && MANYVERSE_DEVELOPMENT=1 npm run electron",
"desktop-debug": "cd desktop && MANYVERSE_DEVELOPMENT=1 npm run debug-electron",
"desktop": "cd desktop && cross-env MANYVERSE_DEVELOPMENT=1 npm run electron",
"desktop-debug": "cd desktop && cross-env MANYVERSE_DEVELOPMENT=1 npm run debug-electron",
"start": "npm run lib && npm run propagate-replacements && react-native start",
"psdr": "./tools/print-service-desk-report.js",
"report-libraries": "./tools/report-libraries.mjs",
Expand Down
29 changes: 24 additions & 5 deletions tools/build-backend.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import util from 'util';
import ora from 'ora';
import childProcess from 'child_process';
import {createRequire} from 'module';
const require = createRequire(import.meta.url);

const fsExtra = require('fs-extra');

const exec = util.promisify(childProcess.exec);
const loading = ora('...').start();
Expand Down Expand Up @@ -101,7 +105,6 @@ async function runAndReport(label, task) {
}),
);
} else {

await runAndReport(
'Apply patches to node modules',
exec('npm run apply-patches', {
Expand All @@ -113,9 +116,13 @@ async function runAndReport(label, task) {
if (targetPlatform === 'desktop') {
await runAndReport(
'Update package-lock.json in ./src/backend',
exec(
'cp ./desktop/package-lock.json ' + './src/backend/package-lock.json',
),
// Use fs-extra to support Windows
fsExtra
.copy('./desktop/package-lock.json', './src/backend/package-lock.json')
.then(
() => ({stdout: '', stderr: ''}),
() => ({stdout: '', stderr: 'Failed to copy package-lock.json'}),
),
);
} else {
await runAndReport(
Expand Down Expand Up @@ -188,7 +195,19 @@ async function runAndReport(label, task) {
if (targetPlatform === 'desktop') {
await runAndReport(
'Remove patches from the desktop folder',
exec('rm -rf ./desktop/patches &&' + 'rm ./desktop/package-lock.json'),
// Use fs-extra to support Windows
fsExtra.rmdir('./desktop/patches', {recursive: true}).then(
() => ({stdout: '', stderr: ''}),
() => ({stdout: '', stderr: 'Failed to remove patches folder'}),
),
);
await runAndReport(
'Remove package-lock.json from the desktop folder',
// Use fs-extra to support Windows
fsExtra.rm('./desktop/package-lock.json').then(
() => ({stdout: '', stderr: ''}),
() => ({stdout: '', stderr: 'Failed to remove package-lock.json'}),
),
);
}
})();

0 comments on commit cb669fe

Please sign in to comment.