mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 03:10:44 -05:00
Add --arch
and --platform
options to NPM build commands to support cross-compiling (!247)
A previous commit 03ae37ec2f hardcoded windows x64 into the build options for build automation. This change restores the ability to build the server using the builder's architecture and platform to the default behavior and adds support for cross-compling via optional parameters `--arch` and `--platform`. The option can be used by `npm run build:release -- --arch=x64 --platform=win32`. Note the `--` in the middle is to tell npm whatever comes next, is for the script, not npm. Additionally, the copy pnpm executables step has been changed to download pnpm release for the correct platform directly from the npm registry. Co-authored-by: qe201020335 <qe201020335@sina.com> Reviewed-on: SPT-AKI/Server#247 Co-authored-by: qe201020335 <qe201020335@noreply.dev.sp-tarkov.com> Co-committed-by: qe201020335 <qe201020335@noreply.dev.sp-tarkov.com>
This commit is contained in:
parent
5ea7d7b97d
commit
c17ab30d4d
@ -7,12 +7,28 @@ import pkgfetch from "@yao-pkg/pkg-fetch";
|
|||||||
import gulp from "gulp";
|
import gulp from "gulp";
|
||||||
import { exec } from "gulp-execa";
|
import { exec } from "gulp-execa";
|
||||||
import rename from "gulp-rename";
|
import rename from "gulp-rename";
|
||||||
|
import download from "gulp-download";
|
||||||
|
import decompress from "gulp-decompress";
|
||||||
|
import minimist from "minimist";
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
import * as ResEdit from "resedit";
|
import * as ResEdit from "resedit";
|
||||||
import manifest from "./package.json" assert { type: "json" };
|
import manifest from "./package.json" assert { type: "json" };
|
||||||
|
|
||||||
const arch = "x64";
|
const knownOptions = {
|
||||||
const platform = "win32";
|
string: ["arch", "platform"],
|
||||||
|
default: {
|
||||||
|
arch: process.arch,
|
||||||
|
platform: process.platform
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const options = minimist(process.argv.slice(2), knownOptions)
|
||||||
|
|
||||||
|
const targetArch = options.arch;
|
||||||
|
const targetPlatform = options.platform;
|
||||||
|
|
||||||
|
console.log(`target arch: ${targetArch}, target platform: ${targetPlatform}`)
|
||||||
|
|
||||||
const nodeVersion = "node20"; // As of @yao-pkg/pkg-fetch v3.5.7, it's v20.10.0
|
const nodeVersion = "node20"; // As of @yao-pkg/pkg-fetch v3.5.7, it's v20.10.0
|
||||||
const stdio = "inherit";
|
const stdio = "inherit";
|
||||||
const buildDir = "build/";
|
const buildDir = "build/";
|
||||||
@ -39,9 +55,9 @@ const fetchPackageImage = async () =>
|
|||||||
{
|
{
|
||||||
const output = "./.pkg-cache/v3.5";
|
const output = "./.pkg-cache/v3.5";
|
||||||
const fetchedPkg = await pkgfetch.need({
|
const fetchedPkg = await pkgfetch.need({
|
||||||
arch: arch,
|
arch: targetArch,
|
||||||
nodeRange: nodeVersion,
|
nodeRange: nodeVersion,
|
||||||
platform: platform,
|
platform: targetPlatform,
|
||||||
output,
|
output,
|
||||||
});
|
});
|
||||||
console.log(`fetched node binary at ${fetchedPkg}`);
|
console.log(`fetched node binary at ${fetchedPkg}`);
|
||||||
@ -57,10 +73,10 @@ const fetchPackageImage = async () =>
|
|||||||
|
|
||||||
const updateBuildProperties = async () =>
|
const updateBuildProperties = async () =>
|
||||||
{
|
{
|
||||||
if (os.platform() !== "win32")
|
if (targetPlatform !== "win32")
|
||||||
{
|
{
|
||||||
console.debug("Attempting to update Windows executable properties on non-Windows platform.");
|
// can't modify executable's resource on non-windows build
|
||||||
// Refringe was here. He's not sorry.
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const exe = ResEdit.NtExecutable.from(await fs.readFile(serverExe));
|
const exe = ResEdit.NtExecutable.from(await fs.readFile(serverExe));
|
||||||
@ -102,10 +118,16 @@ const copyAssets = () =>
|
|||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy executables from node_modules
|
* Download pnpm executable
|
||||||
*/
|
*/
|
||||||
const copyExecutables = () =>
|
const downloadPnpm = async () => {
|
||||||
gulp.src(["node_modules/@pnpm/exe/**/*"]).pipe(gulp.dest(path.join(dataDir, "@pnpm", "exe")));
|
const pnpmVersion = manifest.devDependencies["@pnpm/exe"];
|
||||||
|
const pnpmPackageName = `@pnpm/${targetPlatform === "win32" ? "win" : targetPlatform}-${targetArch}`;
|
||||||
|
const npmResult = await exec(`npm view ${pnpmPackageName}@${pnpmVersion} dist.tarball`, {stdout: "pipe"});
|
||||||
|
const pnpmLink = npmResult.stdout.trim()
|
||||||
|
console.log(`Downloading pnpm binary from ${pnpmLink}`)
|
||||||
|
download(pnpmLink).pipe(decompress({strip: 1})).pipe(gulp.dest(path.join(dataDir, "@pnpm", "exe")));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rename and copy the license file
|
* Rename and copy the license file
|
||||||
@ -153,7 +175,7 @@ const createHashFile = async () =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Combine all tasks into addAssets
|
// Combine all tasks into addAssets
|
||||||
const addAssets = gulp.series(copyAssets, copyExecutables, copyLicense, writeCommitHashToCoreJSON, createHashFile);
|
const addAssets = gulp.series(copyAssets, downloadPnpm, copyLicense, writeCommitHashToCoreJSON, createHashFile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleans the build directory.
|
* Cleans the build directory.
|
||||||
@ -283,7 +305,7 @@ const build = (packagingType) =>
|
|||||||
// Packaging Arguments
|
// Packaging Arguments
|
||||||
const packaging = async (entry) =>
|
const packaging = async (entry) =>
|
||||||
{
|
{
|
||||||
const target = `${nodeVersion}-${platform}-${arch}`;
|
const target = `${nodeVersion}-${targetPlatform}-${targetArch}`;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await pkg.exec([
|
await pkg.exec([
|
||||||
|
1170
project/package-lock.json
generated
1170
project/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -67,9 +67,12 @@
|
|||||||
"dprint": "0.44.0",
|
"dprint": "0.44.0",
|
||||||
"eslint": "8.56.0",
|
"eslint": "8.56.0",
|
||||||
"gulp": "4.0.2",
|
"gulp": "4.0.2",
|
||||||
|
"gulp-decompress": "3.0.0",
|
||||||
|
"gulp-download": "0.0.1",
|
||||||
"gulp-execa": "6.0.0",
|
"gulp-execa": "6.0.0",
|
||||||
"gulp-rename": "2.0.0",
|
"gulp-rename": "2.0.0",
|
||||||
"madge": "6.1.0",
|
"madge": "6.1.0",
|
||||||
|
"minimist": "1.2.8",
|
||||||
"resedit": "2.0.0",
|
"resedit": "2.0.0",
|
||||||
"ts-node-dev": "2.0.0",
|
"ts-node-dev": "2.0.0",
|
||||||
"tsconfig-paths": "4.2.0",
|
"tsconfig-paths": "4.2.0",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user