Files
LiveSplitOne/buildCore.js
T
Christopher Serr 349d95ebb0 Context Menu, CSS Modules and React 19 (#1015)
This replaces the context menu with our own. By doing that we no longer
need to force install our npm packages, as there are no longer any
conflicts. In fact, as part of this change, I updated us to the latest
React 19 and even enabled the React compiler.

I also explored CSS modules for the first time, which are going to allow
us to reduce conflicts between CSS rules and possibly even allow us to
fully remove SASS, as the need for it is going to be reduced.

I also found out that the latest Rust nightly is broken due to their
update to LLVM 20. So I pinned the version to the last working nightly
version.
2025-02-20 21:40:55 +00:00

94 lines
3.3 KiB
JavaScript

import { execSync } from "child_process";
import fs from "fs";
let toolchain = "";
let profile = "debug";
let cargoFlags = "";
// Keep .github/workflows/ci.yml in sync with these flags, so wasm-opt works.
let rustFlags =
"-C target-feature=+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext,+simd128,+extended-const,+multivalue,+reference-types,+tail-call";
let wasmBindgenFlags = "--encode-into always --target web --reference-types";
let target = "wasm32-unknown-unknown";
let targetFolder = target;
if (process.argv.some((v) => v === "--max-opt")) {
// Do a fully optimized build ready for deployment.
profile = "max-opt";
cargoFlags = "--profile max-opt";
} else if (process.argv.some((v) => v === "--release")) {
// Do an optimized build.
profile = "release";
cargoFlags = "--release";
} else {
// Do a debug build.
wasmBindgenFlags += " --keep-debug";
}
// Use WASM features that may not be supported by all the browsers.
if (process.argv.some((v) => v === "--unstable")) {
// Relaxed SIMD is not supported by Firefox and Safari yet.
rustFlags += ",+relaxed-simd";
// Not supported by any browser yet.
rustFlags += ",+wide-arithmetic";
}
// Use the nightly toolchain, which enables some more optimizations.
if (process.argv.some((v) => v === "--nightly")) {
// FIXME: Nightly is broken since the LLVM 20 upgrade. We need to wait for
// stdarch (which has the fix already) to be updated:
// https://github.com/rust-lang/stdarch/pull/1719
toolchain = "+nightly-2025-02-17";
cargoFlags +=
" -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort";
rustFlags += " -Z wasm-c-abi=spec";
// FIXME: Apparently the multivalue ABI is broken again.
// Caused by: https://github.com/rust-lang/rust/pull/135534
// target = "../wasm32-multivalue.json";
// targetFolder = "wasm32-multivalue";
// Virtual function elimination requires LTO, so we can only do it for
// max-opt builds.
if (profile == "max-opt") {
// Seems like cargo itself calls rustc to check for file name patterns,
// but it forgets to pass the LTO flag that we specified in the
// Cargo.toml, so the virtual-function-elimination complains that it's
// only compatible with LTO, so we have to specify lto here too.
// FIXME: Seems to be broken at the moment.
// rustFlags += " -Z virtual-function-elimination -C lto";
}
}
execSync(`cargo ${toolchain} run`, {
cwd: "livesplit-core/capi/bind_gen",
stdio: "inherit",
});
execSync(
`cargo ${toolchain} rustc -p livesplit-core-capi --crate-type cdylib --features wasm-web,web-rendering --target ${target} ${cargoFlags}`,
{
cwd: "livesplit-core",
stdio: "inherit",
env: {
...process.env,
RUSTFLAGS: rustFlags,
},
}
);
execSync(
`wasm-bindgen ${wasmBindgenFlags} livesplit-core/target/${targetFolder}/${profile}/livesplit_core.wasm --out-dir src/livesplit-core`,
{
stdio: "inherit",
}
);
fs.createReadStream(
"livesplit-core/capi/bindings/wasm_bindgen/web/index.ts"
).pipe(fs.createWriteStream("src/livesplit-core/index.ts"));
fs.createReadStream(
"livesplit-core/capi/bindings/wasm_bindgen/web/preload.ts"
).pipe(fs.createWriteStream("src/livesplit-core/preload.ts"));