From df723f8f67a6870836f32b28ae996441f5891956 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Tue, 3 Jun 2025 17:39:34 +0200 Subject: [PATCH 01/12] ability to load a file to input build configuration ; feature gate serialization and debug render --- Cargo.lock | 47 ++++++- builds/prepare_builds/Cargo.toml | 2 + builds/prepare_builds/assets/dim2.ron | 12 ++ .../assets/dim2_deterministic.ron | 13 ++ builds/prepare_builds/assets/dim2_simd.ron | 15 +++ builds/prepare_builds/assets/dim3.ron | 12 ++ .../assets/dim3_deterministic.ron | 13 ++ builds/prepare_builds/assets/dim3_simd.ron | 15 +++ .../assets/example_dim2_minimal.ron | 11 ++ .../assets/example_dim3_minimal.ron | 11 ++ builds/prepare_builds/prepare_all_projects.sh | 2 +- builds/prepare_builds/src/main.rs | 124 ++++++++++++------ .../prepare_builds/templates/Cargo.toml.tera | 10 +- .../templates/build_typescript.sh.tera | 6 + rapier-compat/gen_src.sh | 6 +- rapier-compat/package.json | 3 +- src.ts/pipeline/index.ts | 4 + src.ts/pipeline/world.ts | 40 +++++- src/lib.rs | 2 + src/pipeline/mod.rs | 4 + 20 files changed, 292 insertions(+), 60 deletions(-) create mode 100644 builds/prepare_builds/assets/dim2.ron create mode 100644 builds/prepare_builds/assets/dim2_deterministic.ron create mode 100644 builds/prepare_builds/assets/dim2_simd.ron create mode 100644 builds/prepare_builds/assets/dim3.ron create mode 100644 builds/prepare_builds/assets/dim3_deterministic.ron create mode 100644 builds/prepare_builds/assets/dim3_simd.ron create mode 100644 builds/prepare_builds/assets/example_dim2_minimal.ron create mode 100644 builds/prepare_builds/assets/example_dim3_minimal.ron diff --git a/Cargo.lock b/Cargo.lock index 72692f57..501bd464 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -106,6 +106,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bincode" version = "1.3.3" @@ -369,7 +375,7 @@ dependencies = [ [[package]] name = "dimforge_rapier2d" -version = "0.17.0" +version = "0.17.3" dependencies = [ "bincode", "js-sys", @@ -383,7 +389,7 @@ dependencies = [ [[package]] name = "dimforge_rapier2d-deterministic" -version = "0.17.0" +version = "0.17.3" dependencies = [ "bincode", "js-sys", @@ -397,7 +403,21 @@ dependencies = [ [[package]] name = "dimforge_rapier2d-simd" -version = "0.17.0" +version = "0.17.3" +dependencies = [ + "bincode", + "js-sys", + "nalgebra", + "palette", + "rapier2d", + "ref-cast", + "serde", + "wasm-bindgen", +] + +[[package]] +name = "dimforge_rapier2d-without-serialization" +version = "0.17.3" dependencies = [ "bincode", "js-sys", @@ -411,7 +431,7 @@ dependencies = [ [[package]] name = "dimforge_rapier3d" -version = "0.17.0" +version = "0.17.3" dependencies = [ "bincode", "js-sys", @@ -425,7 +445,7 @@ dependencies = [ [[package]] name = "dimforge_rapier3d-deterministic" -version = "0.17.0" +version = "0.17.3" dependencies = [ "bincode", "js-sys", @@ -439,7 +459,7 @@ dependencies = [ [[package]] name = "dimforge_rapier3d-simd" -version = "0.17.0" +version = "0.17.3" dependencies = [ "bincode", "js-sys", @@ -1008,6 +1028,8 @@ version = "0.1.0" dependencies = [ "clap", "clap_derive", + "ron", + "serde", "tera", ] @@ -1191,6 +1213,19 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cbf4a6aa5f6d6888f39e980649f3ad6b666acdce1d78e95b8a2cb076e687ae30" +[[package]] +name = "ron" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "beceb6f7bf81c73e73aeef6dd1356d9a1b2b4909e1f0fc3e59b034f9572d7b7f" +dependencies = [ + "base64", + "bitflags", + "serde", + "serde_derive", + "unicode-ident", +] + [[package]] name = "rstar" version = "0.12.2" diff --git a/builds/prepare_builds/Cargo.toml b/builds/prepare_builds/Cargo.toml index 905de28f..93b26bfc 100644 --- a/builds/prepare_builds/Cargo.toml +++ b/builds/prepare_builds/Cargo.toml @@ -7,3 +7,5 @@ edition = "2021" clap = { version = "4.5" } clap_derive = { version = "4.5" } tera = "1.20" +ron = "0.10" +serde = { version = "1", features = ["derive"] } diff --git a/builds/prepare_builds/assets/dim2.ron b/builds/prepare_builds/assets/dim2.ron new file mode 100644 index 00000000..31b0690f --- /dev/null +++ b/builds/prepare_builds/assets/dim2.ron @@ -0,0 +1,12 @@ +( + dim: "2", + feature_set: [ + "serde-serialize", + "debug-render", + ], + target_dir: "../rapier2d/", + template_dir: "./templates/", + additional_rust_flags: "", + additional_wasm_opt_flags: [], + js_package_name: "rapier2d" +) \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim2_deterministic.ron b/builds/prepare_builds/assets/dim2_deterministic.ron new file mode 100644 index 00000000..89d477ad --- /dev/null +++ b/builds/prepare_builds/assets/dim2_deterministic.ron @@ -0,0 +1,13 @@ +( + dim: "2", + feature_set: [ + "serde-serialize", + "debug-render", + "enhanced-determinism", + ], + target_dir: "../rapier2d/", + template_dir: "./templates/", + additional_rust_flags: "", + additional_wasm_opt_flags: [], + js_package_name: "rapier2d" +) \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim2_simd.ron b/builds/prepare_builds/assets/dim2_simd.ron new file mode 100644 index 00000000..d5597374 --- /dev/null +++ b/builds/prepare_builds/assets/dim2_simd.ron @@ -0,0 +1,15 @@ +( + dim: "2", + feature_set: [ + "serde-serialize", + "debug-render", + "simd-stable", + ], + target_dir: "../rapier2d-simd", + template_dir: "./templates/", + additional_rust_flags: "RUSTFLAGS=\'-C target-feature=+simd128\'", + additional_wasm_opt_flags: [ + "--enable-simd", + ], + js_package_name: "rapier2d-simd", +) \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim3.ron b/builds/prepare_builds/assets/dim3.ron new file mode 100644 index 00000000..31b0690f --- /dev/null +++ b/builds/prepare_builds/assets/dim3.ron @@ -0,0 +1,12 @@ +( + dim: "2", + feature_set: [ + "serde-serialize", + "debug-render", + ], + target_dir: "../rapier2d/", + template_dir: "./templates/", + additional_rust_flags: "", + additional_wasm_opt_flags: [], + js_package_name: "rapier2d" +) \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim3_deterministic.ron b/builds/prepare_builds/assets/dim3_deterministic.ron new file mode 100644 index 00000000..ea37791c --- /dev/null +++ b/builds/prepare_builds/assets/dim3_deterministic.ron @@ -0,0 +1,13 @@ +( + dim: "3", + feature_set: [ + "serde-serialize", + "debug-render", + "enhanced-determinism", + ], + target_dir: "../rapier3d-deterministic", + template_dir: "./templates/", + additional_rust_flags: "", + additional_wasm_opt_flags: [], + js_package_name: "rapier3d-deterministic", +) \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim3_simd.ron b/builds/prepare_builds/assets/dim3_simd.ron new file mode 100644 index 00000000..5a434b34 --- /dev/null +++ b/builds/prepare_builds/assets/dim3_simd.ron @@ -0,0 +1,15 @@ +( + dim: "3", + feature_set: [ + "serde-serialize", + "debug-render", + "simd-stable", + ], + target_dir: "../rapier3d-simd", + template_dir: "./templates/", + additional_rust_flags: "RUSTFLAGS=\'-C target-feature=+simd128\'", + additional_wasm_opt_flags: [ + "--enable-simd", + ], + js_package_name: "rapier3d-simd", +) \ No newline at end of file diff --git a/builds/prepare_builds/assets/example_dim2_minimal.ron b/builds/prepare_builds/assets/example_dim2_minimal.ron new file mode 100644 index 00000000..bd1d6bb9 --- /dev/null +++ b/builds/prepare_builds/assets/example_dim2_minimal.ron @@ -0,0 +1,11 @@ +// This configuration is not published, but shows how to configure your own builds using the same tooling from ci. +( + dim: "2", + // No features so we are building without serialization, debug render, simd... + feature_set:[], + target_dir: "../rapier2d_minimal/", + template_dir: "./templates/", + additional_rust_flags: "", + additional_wasm_opt_flags: [], + js_package_name: "rapier2d-minimal" +) \ No newline at end of file diff --git a/builds/prepare_builds/assets/example_dim3_minimal.ron b/builds/prepare_builds/assets/example_dim3_minimal.ron new file mode 100644 index 00000000..6b7f5a4f --- /dev/null +++ b/builds/prepare_builds/assets/example_dim3_minimal.ron @@ -0,0 +1,11 @@ +// This configuration is not published, but shows how to configure your own builds using the same tooling from ci. +( + dim: "3", + // No features so we are building without serialization, debug render, simd... + feature_set:[], + target_dir: "../rapier3d_minimal/", + template_dir: "./templates/", + additional_rust_flags: "", + additional_wasm_opt_flags: [], + js_package_name: "rapier3d-minimal" +) \ No newline at end of file diff --git a/builds/prepare_builds/prepare_all_projects.sh b/builds/prepare_builds/prepare_all_projects.sh index bed9c147..7c3b8c1d 100755 --- a/builds/prepare_builds/prepare_all_projects.sh +++ b/builds/prepare_builds/prepare_all_projects.sh @@ -6,6 +6,6 @@ dims=(dim2 dim3) for feature in ${features[@]}; do for dim in ${dims[@]}; do echo "preparing dimension $dim with feature $feature" - cargo run -p prepare_builds -- -d ${dim} -f ${feature} + cargo run -p prepare_builds -- preset -d ${dim} -f ${feature} done done diff --git a/builds/prepare_builds/src/main.rs b/builds/prepare_builds/src/main.rs index 56675e8e..b7762a50 100644 --- a/builds/prepare_builds/src/main.rs +++ b/builds/prepare_builds/src/main.rs @@ -6,20 +6,33 @@ use std::{ }; use clap::Parser; -use clap_derive::{Parser, ValueEnum}; +use clap_derive::{Parser, Subcommand, ValueEnum}; +use serde::{Deserialize, Serialize}; use tera::{Context, Tera}; /// Simple program to greet a person #[derive(Parser, Debug)] #[command(version, about, long_about = None)] pub struct Args { - /// Dimension to use - #[arg(short, long)] - dim: Dimension, + #[command(subcommand)] + command: Commands, +} - /// Features to enable - #[arg(short, long)] - feature_set: FeatureSet, +#[derive(Debug, Subcommand)] +enum Commands { + Preset { + /// Dimension to use + #[arg(short, long, requires = "feature_set")] + dim: Dimension, + + /// Features to enable + #[arg(short, long, requires = "dim")] + feature_set: FeatureSet, + }, + Load { + #[arg(short, long, value_name = "FILE")] + path: PathBuf, + }, } #[derive(ValueEnum, Debug, Clone, Copy)] @@ -36,6 +49,7 @@ pub enum FeatureSet { Simd, } +#[derive(Deserialize, Serialize)] /// Values to use when creating the new build folder. pub struct BuildValues { /// Only the number of dimensions, as sometimes it will be prefixed by "dim" and sometimes post-fixed by "d". @@ -51,48 +65,73 @@ pub struct BuildValues { impl BuildValues { pub fn new(args: Args) -> Self { - let dim = match args.dim { - Dimension::Dim2 => "2", - Dimension::Dim3 => "3", - }; - let feature_set = match args.feature_set { - FeatureSet::NonDeterministic => vec![], - FeatureSet::Deterministic => vec!["enhanced-determinism"], - FeatureSet::Simd => vec!["simd-stable"], - }; - let js_package_name = match args.feature_set { - FeatureSet::NonDeterministic => format!("rapier{dim}d"), - FeatureSet::Deterministic => format!("rapier{dim}d-deterministic"), - FeatureSet::Simd => format!("rapier{dim}d-simd"), - }; - - let root: PathBuf = env!("CARGO_MANIFEST_DIR").into(); - - Self { - dim: dim.to_string(), - feature_set: feature_set.iter().map(|f| f.to_string()).collect(), - template_dir: root.join("templates/").clone(), - target_dir: root.parent().unwrap().join(&js_package_name).into(), - additional_rust_flags: match args.feature_set { - FeatureSet::Simd => "RUSTFLAGS='-C target-feature=+simd128'".to_string(), - _ => "".to_string(), - }, - additional_wasm_opt_flags: match args.feature_set { - FeatureSet::Simd => vec!["--enable-simd".to_string()], - _ => vec![], - }, - js_package_name, + match args.command { + Commands::Preset { dim, feature_set } => { + let dim = match dim { + Dimension::Dim2 => "2", + Dimension::Dim3 => "3", + }; + let feature_set_strings = match feature_set { + FeatureSet::NonDeterministic => vec![], + FeatureSet::Deterministic => vec!["enhanced-determinism"], + FeatureSet::Simd => vec!["simd-stable"], + }; + let js_package_name = match feature_set { + FeatureSet::NonDeterministic => format!("rapier{dim}d"), + FeatureSet::Deterministic => format!("rapier{dim}d-deterministic"), + FeatureSet::Simd => format!("rapier{dim}d-simd"), + }; + + let root: PathBuf = env!("CARGO_MANIFEST_DIR").into(); + + Self { + dim: dim.to_string(), + feature_set: feature_set_strings.iter().map(|f| f.to_string()).collect(), + template_dir: root.join("templates/").clone(), + target_dir: root.parent().unwrap().join(&js_package_name).into(), + additional_rust_flags: match feature_set { + FeatureSet::Simd => "RUSTFLAGS='-C target-feature=+simd128'".to_string(), + _ => "".to_string(), + }, + additional_wasm_opt_flags: match feature_set { + FeatureSet::Simd => vec!["--enable-simd".to_string()], + _ => vec![], + }, + js_package_name, + } + } + Commands::Load { path } => { + let f = File::open(path).expect("Failed opening file"); + let config: Self = match ron::de::from_reader(f) { + Ok(x) => x, + Err(e) => { + println!("Failed to load config: {}", e); + + std::process::exit(1); + } + }; + config + } } } } fn main() { let args = Args::parse(); - dbg!(&args); + //dbg!(&args); let build_values = BuildValues::new(args); + println!( + "RON:\n{}\n", + ron::ser::to_string_pretty(&build_values, ron::ser::PrettyConfig::default()).unwrap() + ); copy_top_level_files_in_directory(&build_values.template_dir, &build_values.target_dir) - .expect("Failed to copy directory"); + .unwrap_or_else(|_| { + eprintln!( + "Failed to copy {:?} into {:?}", + &build_values.template_dir, &build_values.target_dir + ); + }); process_templates(&build_values).expect("Failed to process templates"); } @@ -144,8 +183,7 @@ fn process_templates(build_values: &BuildValues) -> std::io::Result<()> { } }; dbg!(tera.templates.keys(), &context); - - for entry in fs::read_dir(target_dir)? { + for entry in fs::read_dir(dbg!(target_dir))? { let entry = entry?; let path = entry.path(); // For tera templates, remove extension. @@ -162,7 +200,7 @@ fn process_templates(build_values: &BuildValues) -> std::io::Result<()> { Ok(s) => { let old_path = path.clone(); let new_path = path.with_extension(""); - let mut file = File::create(path.join(new_path))?; + let mut file = File::create(path.parent().unwrap().join(new_path))?; file.write_all(s.as_bytes())?; std::fs::remove_file(old_path)?; } diff --git a/builds/prepare_builds/templates/Cargo.toml.tera b/builds/prepare_builds/templates/Cargo.toml.tera index 208addd5..88d71dd7 100644 --- a/builds/prepare_builds/templates/Cargo.toml.tera +++ b/builds/prepare_builds/templates/Cargo.toml.tera @@ -14,6 +14,8 @@ edition = "2018" [features] default = ["dim{{ dimension }}"] dim{{ dimension }} = [] +debug-render = ["rapier{{ dimension }}d/debug-render", "dep:palette"] +serde-serialize = ["rapier{{ dimension }}d/serde-serialize", "dep:serde", "dep:bincode"] [lib] name = "rapier_wasm{{ dimension }}d" @@ -28,8 +30,6 @@ rust.unexpected_cfgs = { level = "warn", check-cfg = [ [dependencies] rapier{{ dimension }}d = { version = "0.26.1", features = [ - "serde-serialize", - "debug-render", {%- for feature in additional_features %} "{{ feature }}", {%- endfor %} @@ -38,9 +38,9 @@ ref-cast = "1" wasm-bindgen = "0.2.100" js-sys = "0.3" nalgebra = "0.33" -serde = { version = "1", features = ["derive", "rc"] } -bincode = "1" -palette = "0.7" +serde = { version = "1", features = ["derive", "rc"], optional = true } +bincode = { version = "1", optional = true } +palette = { version = "0.7", optional = true } [package.metadata.wasm-pack.profile.release] # add -g to keep debug symbols diff --git a/builds/prepare_builds/templates/build_typescript.sh.tera b/builds/prepare_builds/templates/build_typescript.sh.tera index 8fcce98b..4b8e813d 100755 --- a/builds/prepare_builds/templates/build_typescript.sh.tera +++ b/builds/prepare_builds/templates/build_typescript.sh.tera @@ -6,6 +6,12 @@ rm -f ./pkg/raw.ts echo 'export * from "./rapier_wasm{{ dimension }}d"' > pkg/src/raw.ts # See https://serverfault.com/a/137848 find pkg/ -type f -print0 | LC_ALL=C xargs -0 sed -i.bak '\:#if DIM{% if dimension == "2" %}3{% else %}2{% endif %}:,\:#endif:d' +{% if "serde-serialize" not in additional_features -%} +find pkg/ -type f -print0 | LC_ALL=C xargs -0 sed -i.bak '\:#if SERDE_SERIALIZE:,\:#endif:d' +{% endif -%} +{% if "debug-render" not in additional_features -%} +find pkg/ -type f -print0 | LC_ALL=C xargs -0 sed -i.bak '\:#if DEBUG_RENDER:,\:#endif:d' +{% endif -%} npx tsc # NOTE: we keep the typescripts files into the NPM package for source mapping: see #3 sed -i.bak 's/"module": "rapier_wasm{{ dimension }}d.js"/"module": "rapier.js"/g' pkg/package.json diff --git a/rapier-compat/gen_src.sh b/rapier-compat/gen_src.sh index 24ccc441..04c3adaf 100755 --- a/rapier-compat/gen_src.sh +++ b/rapier-compat/gen_src.sh @@ -6,6 +6,7 @@ gen_js() { GENOUT="./gen${DIM}" # Make output directories + rm -rf ${GENOUT} mkdir -p ${GENOUT} # Copy common sources @@ -29,7 +30,7 @@ find gen3d/ -type f -name '*.bak' | xargs rm for features_set in \ "2" "2 deterministic" "2 simd" \ -"3" "3 deterministic" "3 simd" +"3" "3 deterministic" "3 simd" "3" do set -- $features_set # Convert the "tuple" into the param args $1 $2... @@ -39,7 +40,8 @@ do else feature="${1}d-${2}"; fi - + + rm -rf ./builds/${feature}/pkg/ mkdir -p ./builds/${feature}/pkg/ cp ./builds/${feature}/wasm-build/rapier_wasm* ./builds/${feature}/pkg/ diff --git a/rapier-compat/package.json b/rapier-compat/package.json index f97e9cf4..539f8ed1 100644 --- a/rapier-compat/package.json +++ b/rapier-compat/package.json @@ -3,6 +3,7 @@ "description": "Build scripts for compatibility package with inlined webassembly as base64.", "private": true, "scripts": { + "prepare-all-projects": "../builds/prepare_builds/prepare_all_projects.sh", "build-rust-2d-non-deterministic": "./build-rust.sh -f non-deterministic -d 2", "build-rust-2d-deterministic": "./build-rust.sh -f deterministic -d 2", "build-rust-2d-simd": "./build-rust.sh -f simd -d 2", @@ -56,4 +57,4 @@ "js" ] } -} +} \ No newline at end of file diff --git a/src.ts/pipeline/index.ts b/src.ts/pipeline/index.ts index 092c1a59..e4eacaac 100644 --- a/src.ts/pipeline/index.ts +++ b/src.ts/pipeline/index.ts @@ -1,7 +1,11 @@ export * from "./world"; export * from "./physics_pipeline"; +// #if SERDE_SERIALIZE export * from "./serialization_pipeline"; +// #endif export * from "./event_queue"; export * from "./physics_hooks"; +// #if DEBUG_RENDER export * from "./debug_render_pipeline"; +// #endif export * from "./query_pipeline"; diff --git a/src.ts/pipeline/world.ts b/src.ts/pipeline/world.ts index 1a7a4372..5292769f 100644 --- a/src.ts/pipeline/world.ts +++ b/src.ts/pipeline/world.ts @@ -2,7 +2,9 @@ import { RawBroadPhase, RawCCDSolver, RawColliderSet, + // #if SERDE_SERIALIZE RawDeserializedWorld, + // #endif RawIntegrationParameters, RawIslandManager, RawImpulseJointSet, @@ -11,8 +13,12 @@ import { RawPhysicsPipeline, RawQueryPipeline, RawRigidBodySet, + // #if SERDE_SERIALIZE RawSerializationPipeline, + // #endif + // #if DEBUG_RENDER RawDebugRenderPipeline, + // #endif } from "../raw"; import { @@ -50,10 +56,14 @@ import { import {Rotation, Vector, VectorOps} from "../math"; import {PhysicsPipeline} from "./physics_pipeline"; import {QueryFilterFlags, QueryPipeline} from "./query_pipeline"; +// #if SERDE_SERIALIZE import {SerializationPipeline} from "./serialization_pipeline"; +// #endif import {EventQueue} from "./event_queue"; import {PhysicsHooks} from "./physics_hooks"; +// #if DEBUG_RENDER import {DebugRenderBuffers, DebugRenderPipeline} from "./debug_render_pipeline"; +// #endif import { KinematicCharacterController, PidAxesMask, @@ -63,7 +73,6 @@ import {Coarena} from "../coarena"; // #if DIM3 import {DynamicRayCastVehicleController} from "../control"; - // #endif /** @@ -85,8 +94,12 @@ export class World { ccdSolver: CCDSolver; queryPipeline: QueryPipeline; physicsPipeline: PhysicsPipeline; + // #if SERDE_SERIALIZE serializationPipeline: SerializationPipeline; + // #endif + // #if DEBUG_RENDER debugRenderPipeline: DebugRenderPipeline; + // #endif characterControllers: Set; pidControllers: Set; @@ -113,8 +126,12 @@ export class World { this.ccdSolver.free(); this.queryPipeline.free(); this.physicsPipeline.free(); + // #if SERDE_SERIALIZE this.serializationPipeline.free(); + // #endif + // #if DEBUG_RENDER this.debugRenderPipeline.free(); + // #endif this.characterControllers.forEach((controller) => controller.free()); this.pidControllers.forEach((controller) => controller.free()); @@ -133,8 +150,12 @@ export class World { this.multibodyJoints = undefined; this.queryPipeline = undefined; this.physicsPipeline = undefined; + // #if SERDE_SERIALIZE this.serializationPipeline = undefined; + // #endif + // #if DEBUG_RENDER this.debugRenderPipeline = undefined; + // #endif this.characterControllers = undefined; this.pidControllers = undefined; @@ -156,8 +177,12 @@ export class World { rawCCDSolver?: RawCCDSolver, rawQueryPipeline?: RawQueryPipeline, rawPhysicsPipeline?: RawPhysicsPipeline, + // #if SERDE_SERIALIZE rawSerializationPipeline?: RawSerializationPipeline, + // #endif + // #if DEBUG_RENDER rawDebugRenderPipeline?: RawDebugRenderPipeline, + // #endif ) { this.gravity = gravity; this.integrationParameters = new IntegrationParameters( @@ -173,12 +198,16 @@ export class World { this.ccdSolver = new CCDSolver(rawCCDSolver); this.queryPipeline = new QueryPipeline(rawQueryPipeline); this.physicsPipeline = new PhysicsPipeline(rawPhysicsPipeline); + // #if SERDE_SERIALIZE this.serializationPipeline = new SerializationPipeline( rawSerializationPipeline, ); + // #endif + // #if DEBUG_RENDER this.debugRenderPipeline = new DebugRenderPipeline( rawDebugRenderPipeline, ); + // #endif this.characterControllers = new Set(); this.pidControllers = new Set(); @@ -186,11 +215,14 @@ export class World { this.vehicleControllers = new Set(); // #endif + // #if SERDE_SERIALIZE this.impulseJoints.finalizeDeserialization(this.bodies); this.bodies.finalizeDeserialization(this.colliders); this.colliders.finalizeDeserialization(this.bodies); + // #endif } + // #if SERDE_SERIALIZE public static fromRaw(raw: RawDeserializedWorld): World { if (!raw) return null; @@ -227,7 +259,7 @@ export class World { ); } - /** + /** * Creates a new physics world from a snapshot. * * This new physics world will be an identical copy of the snapshoted physics world. @@ -236,7 +268,10 @@ export class World { let deser = new SerializationPipeline(); return deser.deserializeAll(data); } + // End serialization block + // #endif + // #if DEBUG_RENDER /** * Computes all the lines (and their colors) needed to render the scene. * @@ -262,6 +297,7 @@ export class World { this.debugRenderPipeline.colors, ); } + // #endif /** * Advance the simulation by one time step. diff --git a/src/lib.rs b/src/lib.rs index 132809dc..92690971 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,8 @@ extern crate nalgebra as na; extern crate rapier2d as rapier; #[cfg(feature = "dim3")] extern crate rapier3d as rapier; + +#[cfg(feature = "serde-serialize")] #[macro_use] extern crate serde; diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs index eabd9cc7..a127c966 100644 --- a/src/pipeline/mod.rs +++ b/src/pipeline/mod.rs @@ -1,13 +1,17 @@ +#[cfg(feature = "debug-render")] pub use self::debug_render_pipeline::*; pub use self::event_queue::*; pub use self::physics_hooks::*; pub use self::physics_pipeline::*; pub use self::query_pipeline::*; +#[cfg(feature = "serde-serialize")] pub use self::serialization_pipeline::*; +#[cfg(feature = "debug-render")] mod debug_render_pipeline; mod event_queue; mod physics_hooks; mod physics_pipeline; mod query_pipeline; +#[cfg(feature = "serde-serialize")] mod serialization_pipeline; From 3c8f5968a9292110af7f5c0a4468d5075d91c806 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 4 Jun 2025 11:20:03 +0200 Subject: [PATCH 02/12] use shared config file for rollup too (wip) ; weird error about simd used in non-simd build --- Cargo.lock | 21 +--- builds/prepare_builds/Cargo.toml | 2 +- builds/prepare_builds/README.md | 3 +- builds/prepare_builds/assets/dim2.json | 12 +++ builds/prepare_builds/assets/dim2.ron | 12 --- .../assets/dim2_deterministic.json | 13 +++ .../assets/dim2_deterministic.ron | 13 --- builds/prepare_builds/assets/dim2_simd.json | 15 +++ builds/prepare_builds/assets/dim2_simd.ron | 15 --- builds/prepare_builds/assets/dim3.json | 12 +++ builds/prepare_builds/assets/dim3.ron | 12 --- .../assets/dim3_deterministic.json | 13 +++ .../assets/dim3_deterministic.ron | 13 --- builds/prepare_builds/assets/dim3_simd.json | 15 +++ builds/prepare_builds/assets/dim3_simd.ron | 15 --- .../assets/example_dim2_minimal.json | 9 ++ .../assets/example_dim2_minimal.ron | 11 --- .../assets/example_dim3_minimal.json | 9 ++ .../assets/example_dim3_minimal.ron | 11 --- builds/prepare_builds/prepare_all_projects.sh | 13 ++- builds/prepare_builds/src/main.rs | 95 +++---------------- .../templates/build_rust.sh.tera | 4 +- rapier-compat/build-rust.sh | 46 ++++----- rapier-compat/package.json | 12 +-- rapier-compat/rollup.config.js | 7 ++ 25 files changed, 160 insertions(+), 243 deletions(-) create mode 100644 builds/prepare_builds/assets/dim2.json delete mode 100644 builds/prepare_builds/assets/dim2.ron create mode 100644 builds/prepare_builds/assets/dim2_deterministic.json delete mode 100644 builds/prepare_builds/assets/dim2_deterministic.ron create mode 100644 builds/prepare_builds/assets/dim2_simd.json delete mode 100644 builds/prepare_builds/assets/dim2_simd.ron create mode 100644 builds/prepare_builds/assets/dim3.json delete mode 100644 builds/prepare_builds/assets/dim3.ron create mode 100644 builds/prepare_builds/assets/dim3_deterministic.json delete mode 100644 builds/prepare_builds/assets/dim3_deterministic.ron create mode 100644 builds/prepare_builds/assets/dim3_simd.json delete mode 100644 builds/prepare_builds/assets/dim3_simd.ron create mode 100644 builds/prepare_builds/assets/example_dim2_minimal.json delete mode 100644 builds/prepare_builds/assets/example_dim2_minimal.ron create mode 100644 builds/prepare_builds/assets/example_dim3_minimal.json delete mode 100644 builds/prepare_builds/assets/example_dim3_minimal.ron diff --git a/Cargo.lock b/Cargo.lock index 501bd464..49fcb62f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -106,12 +106,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - [[package]] name = "bincode" version = "1.3.3" @@ -1028,8 +1022,8 @@ version = "0.1.0" dependencies = [ "clap", "clap_derive", - "ron", "serde", + "serde_json", "tera", ] @@ -1213,19 +1207,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cbf4a6aa5f6d6888f39e980649f3ad6b666acdce1d78e95b8a2cb076e687ae30" -[[package]] -name = "ron" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beceb6f7bf81c73e73aeef6dd1356d9a1b2b4909e1f0fc3e59b034f9572d7b7f" -dependencies = [ - "base64", - "bitflags", - "serde", - "serde_derive", - "unicode-ident", -] - [[package]] name = "rstar" version = "0.12.2" diff --git a/builds/prepare_builds/Cargo.toml b/builds/prepare_builds/Cargo.toml index 93b26bfc..b0fa8907 100644 --- a/builds/prepare_builds/Cargo.toml +++ b/builds/prepare_builds/Cargo.toml @@ -7,5 +7,5 @@ edition = "2021" clap = { version = "4.5" } clap_derive = { version = "4.5" } tera = "1.20" -ron = "0.10" +serde_json = "1" serde = { version = "1", features = ["derive"] } diff --git a/builds/prepare_builds/README.md b/builds/prepare_builds/README.md index 4d05a2fa..5c9dbb98 100644 --- a/builds/prepare_builds/README.md +++ b/builds/prepare_builds/README.md @@ -6,7 +6,8 @@ It uses clap so you can pass `-h` to get more info about its parameters. ## usage -At workspace root: `cargo run -p prepare_builds -- -d dim2 -f simd`. +In this directory: `cargo run -- -c assets/dim2.ron`. +The configuration file contains relative links which are not made canonical so the call location is important. Or use provided scripts: `./builds/prepare_builds/prepare_all_projects.sh && ./builds/prepare_builds/build_all_projects.sh` diff --git a/builds/prepare_builds/assets/dim2.json b/builds/prepare_builds/assets/dim2.json new file mode 100644 index 00000000..633d4a1b --- /dev/null +++ b/builds/prepare_builds/assets/dim2.json @@ -0,0 +1,12 @@ +{ + "dim": "2", + "feature_set": [ + "serde-serialize", + "debug-render" + ], + "target_dir": "../rapier2d/", + "template_dir": "./templates/", + "additional_rust_flags": "", + "additional_wasm_opt_flags": [], + "js_package_name": "rapier2d" +} \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim2.ron b/builds/prepare_builds/assets/dim2.ron deleted file mode 100644 index 31b0690f..00000000 --- a/builds/prepare_builds/assets/dim2.ron +++ /dev/null @@ -1,12 +0,0 @@ -( - dim: "2", - feature_set: [ - "serde-serialize", - "debug-render", - ], - target_dir: "../rapier2d/", - template_dir: "./templates/", - additional_rust_flags: "", - additional_wasm_opt_flags: [], - js_package_name: "rapier2d" -) \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim2_deterministic.json b/builds/prepare_builds/assets/dim2_deterministic.json new file mode 100644 index 00000000..9e1a5d28 --- /dev/null +++ b/builds/prepare_builds/assets/dim2_deterministic.json @@ -0,0 +1,13 @@ +{ + "dim": "2", + "feature_set": [ + "serde-serialize", + "debug-render", + "enhanced-determinism" + ], + "target_dir": "../rapier2d-deterministic", + "template_dir": "./templates/", + "additional_rust_flags": "", + "additional_wasm_opt_flags": [], + "js_package_name": "rapier2d-deterministic" +} \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim2_deterministic.ron b/builds/prepare_builds/assets/dim2_deterministic.ron deleted file mode 100644 index 89d477ad..00000000 --- a/builds/prepare_builds/assets/dim2_deterministic.ron +++ /dev/null @@ -1,13 +0,0 @@ -( - dim: "2", - feature_set: [ - "serde-serialize", - "debug-render", - "enhanced-determinism", - ], - target_dir: "../rapier2d/", - template_dir: "./templates/", - additional_rust_flags: "", - additional_wasm_opt_flags: [], - js_package_name: "rapier2d" -) \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim2_simd.json b/builds/prepare_builds/assets/dim2_simd.json new file mode 100644 index 00000000..0bb36fe0 --- /dev/null +++ b/builds/prepare_builds/assets/dim2_simd.json @@ -0,0 +1,15 @@ +{ + "dim": "2", + "feature_set": [ + "serde-serialize", + "debug-render", + "simd-stable" + ], + "target_dir": "../rapier2d-simd", + "template_dir": "./templates/", + "additional_rust_flags": "-C target-feature=+simd128", + "additional_wasm_opt_flags": [ + "--enable-simd" + ], + "js_package_name": "rapier2d-simd" +} \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim2_simd.ron b/builds/prepare_builds/assets/dim2_simd.ron deleted file mode 100644 index d5597374..00000000 --- a/builds/prepare_builds/assets/dim2_simd.ron +++ /dev/null @@ -1,15 +0,0 @@ -( - dim: "2", - feature_set: [ - "serde-serialize", - "debug-render", - "simd-stable", - ], - target_dir: "../rapier2d-simd", - template_dir: "./templates/", - additional_rust_flags: "RUSTFLAGS=\'-C target-feature=+simd128\'", - additional_wasm_opt_flags: [ - "--enable-simd", - ], - js_package_name: "rapier2d-simd", -) \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim3.json b/builds/prepare_builds/assets/dim3.json new file mode 100644 index 00000000..6e54d4fc --- /dev/null +++ b/builds/prepare_builds/assets/dim3.json @@ -0,0 +1,12 @@ +{ + "dim": "3", + "feature_set": [ + "serde-serialize", + "debug-render" + ], + "target_dir": "../rapier3d/", + "template_dir": "./templates/", + "additional_rust_flags": "", + "additional_wasm_opt_flags": [], + "js_package_name": "rapier3d" +} \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim3.ron b/builds/prepare_builds/assets/dim3.ron deleted file mode 100644 index 31b0690f..00000000 --- a/builds/prepare_builds/assets/dim3.ron +++ /dev/null @@ -1,12 +0,0 @@ -( - dim: "2", - feature_set: [ - "serde-serialize", - "debug-render", - ], - target_dir: "../rapier2d/", - template_dir: "./templates/", - additional_rust_flags: "", - additional_wasm_opt_flags: [], - js_package_name: "rapier2d" -) \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim3_deterministic.json b/builds/prepare_builds/assets/dim3_deterministic.json new file mode 100644 index 00000000..9abf2eae --- /dev/null +++ b/builds/prepare_builds/assets/dim3_deterministic.json @@ -0,0 +1,13 @@ +{ + "dim": "3", + "feature_set": [ + "serde-serialize", + "debug-render", + "enhanced-determinism" + ], + "target_dir": "../rapier3d-deterministic", + "template_dir": "./templates/", + "additional_rust_flags": "", + "additional_wasm_opt_flags": [], + "js_package_name": "rapier3d-deterministic" +} \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim3_deterministic.ron b/builds/prepare_builds/assets/dim3_deterministic.ron deleted file mode 100644 index ea37791c..00000000 --- a/builds/prepare_builds/assets/dim3_deterministic.ron +++ /dev/null @@ -1,13 +0,0 @@ -( - dim: "3", - feature_set: [ - "serde-serialize", - "debug-render", - "enhanced-determinism", - ], - target_dir: "../rapier3d-deterministic", - template_dir: "./templates/", - additional_rust_flags: "", - additional_wasm_opt_flags: [], - js_package_name: "rapier3d-deterministic", -) \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim3_simd.json b/builds/prepare_builds/assets/dim3_simd.json new file mode 100644 index 00000000..29ce6de9 --- /dev/null +++ b/builds/prepare_builds/assets/dim3_simd.json @@ -0,0 +1,15 @@ +{ + "dim": "3", + "feature_set": [ + "serde-serialize", + "debug-render", + "simd-stable" + ], + "target_dir": "../rapier3d-simd", + "template_dir": "./templates/", + "additional_rust_flags": "-C target-feature=+simd128", + "additional_wasm_opt_flags": [ + "--enable-simd" + ], + "js_package_name": "rapier3d-simd" +} \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim3_simd.ron b/builds/prepare_builds/assets/dim3_simd.ron deleted file mode 100644 index 5a434b34..00000000 --- a/builds/prepare_builds/assets/dim3_simd.ron +++ /dev/null @@ -1,15 +0,0 @@ -( - dim: "3", - feature_set: [ - "serde-serialize", - "debug-render", - "simd-stable", - ], - target_dir: "../rapier3d-simd", - template_dir: "./templates/", - additional_rust_flags: "RUSTFLAGS=\'-C target-feature=+simd128\'", - additional_wasm_opt_flags: [ - "--enable-simd", - ], - js_package_name: "rapier3d-simd", -) \ No newline at end of file diff --git a/builds/prepare_builds/assets/example_dim2_minimal.json b/builds/prepare_builds/assets/example_dim2_minimal.json new file mode 100644 index 00000000..7038625b --- /dev/null +++ b/builds/prepare_builds/assets/example_dim2_minimal.json @@ -0,0 +1,9 @@ +{ + "dim": "3", + "feature_set": [], + "target_dir": "../rapier3d/", + "template_dir": "./templates/", + "additional_rust_flags": "", + "additional_wasm_opt_flags": [], + "js_package_name": "rapier3d-minimal" +} \ No newline at end of file diff --git a/builds/prepare_builds/assets/example_dim2_minimal.ron b/builds/prepare_builds/assets/example_dim2_minimal.ron deleted file mode 100644 index bd1d6bb9..00000000 --- a/builds/prepare_builds/assets/example_dim2_minimal.ron +++ /dev/null @@ -1,11 +0,0 @@ -// This configuration is not published, but shows how to configure your own builds using the same tooling from ci. -( - dim: "2", - // No features so we are building without serialization, debug render, simd... - feature_set:[], - target_dir: "../rapier2d_minimal/", - template_dir: "./templates/", - additional_rust_flags: "", - additional_wasm_opt_flags: [], - js_package_name: "rapier2d-minimal" -) \ No newline at end of file diff --git a/builds/prepare_builds/assets/example_dim3_minimal.json b/builds/prepare_builds/assets/example_dim3_minimal.json new file mode 100644 index 00000000..7038625b --- /dev/null +++ b/builds/prepare_builds/assets/example_dim3_minimal.json @@ -0,0 +1,9 @@ +{ + "dim": "3", + "feature_set": [], + "target_dir": "../rapier3d/", + "template_dir": "./templates/", + "additional_rust_flags": "", + "additional_wasm_opt_flags": [], + "js_package_name": "rapier3d-minimal" +} \ No newline at end of file diff --git a/builds/prepare_builds/assets/example_dim3_minimal.ron b/builds/prepare_builds/assets/example_dim3_minimal.ron deleted file mode 100644 index 6b7f5a4f..00000000 --- a/builds/prepare_builds/assets/example_dim3_minimal.ron +++ /dev/null @@ -1,11 +0,0 @@ -// This configuration is not published, but shows how to configure your own builds using the same tooling from ci. -( - dim: "3", - // No features so we are building without serialization, debug render, simd... - feature_set:[], - target_dir: "../rapier3d_minimal/", - template_dir: "./templates/", - additional_rust_flags: "", - additional_wasm_opt_flags: [], - js_package_name: "rapier3d-minimal" -) \ No newline at end of file diff --git a/builds/prepare_builds/prepare_all_projects.sh b/builds/prepare_builds/prepare_all_projects.sh index 7c3b8c1d..8cf35cbd 100755 --- a/builds/prepare_builds/prepare_all_projects.sh +++ b/builds/prepare_builds/prepare_all_projects.sh @@ -1,11 +1,10 @@ #!/bin/bash -features=(non-deterministic deterministic simd) -dims=(dim2 dim3) +cd "$(dirname "$0")" -for feature in ${features[@]}; do - for dim in ${dims[@]}; do - echo "preparing dimension $dim with feature $feature" - cargo run -p prepare_builds -- preset -d ${dim} -f ${feature} - done +config_files=(dim2_deterministic dim2_simd dim2 dim3_deterministic dim3_simd dim3) + +for config_path in ${config_files[@]}; do + echo "preparing dimension $dim with feature $feature" + cargo run -- -c assets/${config_path}.json done diff --git a/builds/prepare_builds/src/main.rs b/builds/prepare_builds/src/main.rs index b7762a50..ebe1465b 100644 --- a/builds/prepare_builds/src/main.rs +++ b/builds/prepare_builds/src/main.rs @@ -6,7 +6,7 @@ use std::{ }; use clap::Parser; -use clap_derive::{Parser, Subcommand, ValueEnum}; +use clap_derive::Parser; use serde::{Deserialize, Serialize}; use tera::{Context, Tera}; @@ -14,45 +14,14 @@ use tera::{Context, Tera}; #[derive(Parser, Debug)] #[command(version, about, long_about = None)] pub struct Args { - #[command(subcommand)] - command: Commands, -} - -#[derive(Debug, Subcommand)] -enum Commands { - Preset { - /// Dimension to use - #[arg(short, long, requires = "feature_set")] - dim: Dimension, - - /// Features to enable - #[arg(short, long, requires = "dim")] - feature_set: FeatureSet, - }, - Load { - #[arg(short, long, value_name = "FILE")] - path: PathBuf, - }, -} - -#[derive(ValueEnum, Debug, Clone, Copy)] -pub enum Dimension { - Dim2, - Dim3, -} - -#[derive(ValueEnum, Default, Debug, Clone, Copy)] -pub enum FeatureSet { - #[default] - NonDeterministic, - Deterministic, - Simd, + #[arg(short, long, value_name = "FILE")] + config_path: PathBuf, } #[derive(Deserialize, Serialize)] /// Values to use when creating the new build folder. pub struct BuildValues { - /// Only the number of dimensions, as sometimes it will be prefixed by "dim" and sometimes post-fixed by "d". + /// Only the number of dimensions (1 or 2), as sometimes it will be prefixed by "dim" and sometimes post-fixed by "d". pub dim: String, /// real name of the additional features to enable in the project pub feature_set: Vec, @@ -65,54 +34,16 @@ pub struct BuildValues { impl BuildValues { pub fn new(args: Args) -> Self { - match args.command { - Commands::Preset { dim, feature_set } => { - let dim = match dim { - Dimension::Dim2 => "2", - Dimension::Dim3 => "3", - }; - let feature_set_strings = match feature_set { - FeatureSet::NonDeterministic => vec![], - FeatureSet::Deterministic => vec!["enhanced-determinism"], - FeatureSet::Simd => vec!["simd-stable"], - }; - let js_package_name = match feature_set { - FeatureSet::NonDeterministic => format!("rapier{dim}d"), - FeatureSet::Deterministic => format!("rapier{dim}d-deterministic"), - FeatureSet::Simd => format!("rapier{dim}d-simd"), - }; + let f = File::open(args.config_path).expect("Failed opening file"); + let config: Self = match serde_json::from_reader(f) { + Ok(x) => x, + Err(e) => { + println!("Failed to load config: {}", e); - let root: PathBuf = env!("CARGO_MANIFEST_DIR").into(); - - Self { - dim: dim.to_string(), - feature_set: feature_set_strings.iter().map(|f| f.to_string()).collect(), - template_dir: root.join("templates/").clone(), - target_dir: root.parent().unwrap().join(&js_package_name).into(), - additional_rust_flags: match feature_set { - FeatureSet::Simd => "RUSTFLAGS='-C target-feature=+simd128'".to_string(), - _ => "".to_string(), - }, - additional_wasm_opt_flags: match feature_set { - FeatureSet::Simd => vec!["--enable-simd".to_string()], - _ => vec![], - }, - js_package_name, - } - } - Commands::Load { path } => { - let f = File::open(path).expect("Failed opening file"); - let config: Self = match ron::de::from_reader(f) { - Ok(x) => x, - Err(e) => { - println!("Failed to load config: {}", e); - - std::process::exit(1); - } - }; - config + std::process::exit(1); } - } + }; + config } } @@ -123,7 +54,7 @@ fn main() { let build_values = BuildValues::new(args); println!( "RON:\n{}\n", - ron::ser::to_string_pretty(&build_values, ron::ser::PrettyConfig::default()).unwrap() + serde_json::to_string_pretty(&build_values).unwrap() ); copy_top_level_files_in_directory(&build_values.template_dir, &build_values.target_dir) .unwrap_or_else(|_| { diff --git a/builds/prepare_builds/templates/build_rust.sh.tera b/builds/prepare_builds/templates/build_rust.sh.tera index 6fd6ae82..73d450d0 100755 --- a/builds/prepare_builds/templates/build_rust.sh.tera +++ b/builds/prepare_builds/templates/build_rust.sh.tera @@ -2,8 +2,10 @@ # Cleaning rust because changing rust flags may lead to different build results. cargo clean +{% if additional_rust_flags -%} +RUSTFLAGS='{{ additional_rust_flags }}' {% else -%} +{%- endif -%} npx wasm-pack build -{{ additional_rust_flags }} npx wasm-pack build sed -i.bak 's#dimforge_rapier#@dimforge/rapier#g' pkg/package.json sed -i.bak 's/"rapier_wasm{{ dimension }}d_bg.wasm"/"*"/g' pkg/package.json ( diff --git a/rapier-compat/build-rust.sh b/rapier-compat/build-rust.sh index 2acd18f8..1fb4f2fb 100755 --- a/rapier-compat/build-rust.sh +++ b/rapier-compat/build-rust.sh @@ -1,36 +1,31 @@ #!/bin/bash - help() { - printf "Usage: %s: [-d 2|3] [-f deterministim|non-deterministic|simd]\n" $0 + printf "Usage: %s: [-c CONFIG_NAME]\n" $0 } -while getopts :d:f: name +while getopts :c: conf_name do - case $name in - d) - dimension="$OPTARG";; - f) - feature="$OPTARG";; + case $conf_name in + c) + config_file_name="$OPTARG" + ;; ?) help ; exit 1;; esac done -if [[ -z "$dimension" ]]; then +if [[ -z "$config_file_name" ]]; then help; exit 2; fi -if [[ -z "$feature" ]]; then - help; exit 3; -fi -if [[ $feature == "non-deterministic" ]]; then - feature_postfix="" -else - feature_postfix="-${feature}" -fi +config_file_path="../builds/prepare_builds/assets/$config_file_name.json" + +rust_source_directory_name=`node -pe 'JSON.parse(process.argv[1]).js_package_name' "$(cat ${config_file_path})"` + +echo "building rust wasm for ${rust_source_directory_name} package." -rust_source_directory="../builds/rapier${dimension}d${feature_postfix}" +rust_source_directory="../builds/${rust_source_directory_name}" if [ ! -d "$rust_source_directory" ]; then echo "Directory $rust_source_directory does not exist"; @@ -39,12 +34,17 @@ if [ ! -d "$rust_source_directory" ]; then exit 4; fi +echo "source folder is: ${rust_source_directory}" + +set -x + +additional_rust_flags=`node -pe 'JSON.parse(process.argv[1]).additional_rust_flags' "$(cat ${config_file_path})"` + + # Working dir in wasm-pack is the project root so we need that "../../" -if [[ $feature == "simd" ]]; then - export additional_rustflags='-C target-feature=+simd128' -else - export additional_rustflags='' +if [[ $additional_rust_flags == "undefined" ]]; then + additional_rust_flags='' fi -RUSTFLAGS="${additional_rustflags}" wasm-pack --verbose build --target web --out-dir "../../rapier-compat/builds/${dimension}d${feature_postfix}/wasm-build" "$rust_source_directory" +RUSTFLAGS="${additional_rust_flags}" wasm-pack --verbose build --target web --out-dir "../../rapier-compat/builds/${rust_source_directory_name}/wasm-build" "$rust_source_directory" diff --git a/rapier-compat/package.json b/rapier-compat/package.json index 539f8ed1..b98fa1de 100644 --- a/rapier-compat/package.json +++ b/rapier-compat/package.json @@ -4,13 +4,13 @@ "private": true, "scripts": { "prepare-all-projects": "../builds/prepare_builds/prepare_all_projects.sh", - "build-rust-2d-non-deterministic": "./build-rust.sh -f non-deterministic -d 2", - "build-rust-2d-deterministic": "./build-rust.sh -f deterministic -d 2", - "build-rust-2d-simd": "./build-rust.sh -f simd -d 2", + "build-rust-2d-non-deterministic": "./build-rust.sh -c dim2", + "build-rust-2d-deterministic": "./build-rust.sh -c dim2_deterministic", + "build-rust-2d-simd": "./build-rust.sh -c dim2_simd", "build-rust-2d-all": "npm run build-rust-2d-non-deterministic && npm run build-rust-2d-deterministic && npm run build-rust-2d-simd", - "build-rust-3d-non-deterministic": "./build-rust.sh -f non-deterministic -d 3", - "build-rust-3d-deterministic": "./build-rust.sh -f deterministic -d 3", - "build-rust-3d-simd": "./build-rust.sh -f simd -d 3", + "build-rust-3d-non-deterministic": "./build-rust.sh -c dim3", + "build-rust-3d-deterministic": "./build-rust.sh -c dim3_deterministic", + "build-rust-3d-simd": "./build-rust.sh -c dim3_simd", "build-rust-3d-all": "npm run build-rust-3d-non-deterministic && npm run build-rust-3d-deterministic && npm run build-rust-3d-simd", "build-rust-all": "npm run build-rust-2d-all && npm run build-rust-3d-all", "build-genjs": "sh ./gen_src.sh", diff --git a/rapier-compat/rollup.config.js b/rapier-compat/rollup.config.js index 7246dd1e..60c12eb6 100644 --- a/rapier-compat/rollup.config.js +++ b/rapier-compat/rollup.config.js @@ -6,6 +6,7 @@ import path from "path"; import {base64} from "rollup-plugin-base64"; import copy from "rollup-plugin-copy"; import filesize from "rollup-plugin-filesize"; +import * as fs from 'fs'; const config = (dim, features_postfix) => ({ input: `builds/${features_postfix}/gen${dim}/rapier.ts`, @@ -68,6 +69,11 @@ const config = (dim, features_postfix) => ({ ], }); +const conf = JSON.parse(fs.readFileSync('../builds/prepare_builds/assets/dim2.json')); + +console.log(conf); + +/* export default [ config("2d", "2d"), config("2d", "2d-deterministic"), @@ -76,3 +82,4 @@ export default [ config("3d", "3d-deterministic"), config("3d", "3d-simd"), ]; +*/ \ No newline at end of file From 93bc0343ca652c2264c448634a84e6d3c814ac7e Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 4 Jun 2025 18:19:47 +0200 Subject: [PATCH 03/12] rapier-compat can now use the conf asset from rust, and generate 1 package only thanks to build_json.sh script --- Cargo.lock | 22 +---- builds/prepare_builds/assets/dim2.json | 5 +- .../assets/dim2_deterministic.json | 5 +- builds/prepare_builds/assets/dim2_simd.json | 5 +- builds/prepare_builds/assets/dim3.json | 5 +- .../assets/dim3_deterministic.json | 5 +- builds/prepare_builds/assets/dim3_simd.json | 5 +- .../assets/example_dim2_minimal.json | 7 +- .../assets/example_dim3_minimal.json | 7 +- builds/prepare_builds/src/main.rs | 3 + .../prepare_builds/templates/Cargo.toml.tera | 19 ++-- .../templates/build_rust.sh.tera | 5 +- .../templates/build_typescript.sh.tera | 15 ++-- rapier-compat/build-rust.sh | 12 +-- rapier-compat/build_conf.sh | 21 +++++ rapier-compat/fix_raw_file.sh | 11 --- rapier-compat/gen_src.sh | 86 +++++++++---------- rapier-compat/package-lock.json | 15 ++-- rapier-compat/package.json | 30 +++---- rapier-compat/rollup.config.js | 40 ++++----- rapier-compat/tsconfig.pkg3d.json | 8 +- 21 files changed, 171 insertions(+), 160 deletions(-) create mode 100755 rapier-compat/build_conf.sh delete mode 100644 rapier-compat/fix_raw_file.sh diff --git a/Cargo.lock b/Cargo.lock index 49fcb62f..17105694 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -409,20 +409,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "dimforge_rapier2d-without-serialization" -version = "0.17.3" -dependencies = [ - "bincode", - "js-sys", - "nalgebra", - "palette", - "rapier2d", - "ref-cast", - "serde", - "wasm-bindgen", -] - [[package]] name = "dimforge_rapier3d" version = "0.17.3" @@ -694,9 +680,9 @@ checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "matrixmultiply" -version = "0.3.9" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9380b911e3e96d10c1f415da0876389aaf1b56759054eeb0de7df940c456ba1a" +checksum = "a06de3016e9fae57a36fd14dba131fccf49f74b40b7fbdb472f96e361ec71a08" dependencies = [ "autocfg", "rawpointer", @@ -1203,9 +1189,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "robust" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf4a6aa5f6d6888f39e980649f3ad6b666acdce1d78e95b8a2cb076e687ae30" +checksum = "4e27ee8bb91ca0adcf0ecb116293afa12d393f9c2b9b9cd54d33e8078fe19839" [[package]] name = "rstar" diff --git a/builds/prepare_builds/assets/dim2.json b/builds/prepare_builds/assets/dim2.json index 633d4a1b..09b3ec15 100644 --- a/builds/prepare_builds/assets/dim2.json +++ b/builds/prepare_builds/assets/dim2.json @@ -8,5 +8,8 @@ "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], - "js_package_name": "rapier2d" + "js_package_name": "rapier2d", + "conditions_to_remove": [ + "DIM3" + ] } \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim2_deterministic.json b/builds/prepare_builds/assets/dim2_deterministic.json index 9e1a5d28..20c08baf 100644 --- a/builds/prepare_builds/assets/dim2_deterministic.json +++ b/builds/prepare_builds/assets/dim2_deterministic.json @@ -9,5 +9,8 @@ "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], - "js_package_name": "rapier2d-deterministic" + "js_package_name": "rapier2d-deterministic", + "conditions_to_remove": [ + "DIM3" + ] } \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim2_simd.json b/builds/prepare_builds/assets/dim2_simd.json index 0bb36fe0..5a0d9e2a 100644 --- a/builds/prepare_builds/assets/dim2_simd.json +++ b/builds/prepare_builds/assets/dim2_simd.json @@ -11,5 +11,8 @@ "additional_wasm_opt_flags": [ "--enable-simd" ], - "js_package_name": "rapier2d-simd" + "js_package_name": "rapier2d-simd", + "conditions_to_remove": [ + "DIM3" + ] } \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim3.json b/builds/prepare_builds/assets/dim3.json index 6e54d4fc..b1887410 100644 --- a/builds/prepare_builds/assets/dim3.json +++ b/builds/prepare_builds/assets/dim3.json @@ -8,5 +8,8 @@ "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], - "js_package_name": "rapier3d" + "js_package_name": "rapier3d", + "conditions_to_remove": [ + "DIM2" + ] } \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim3_deterministic.json b/builds/prepare_builds/assets/dim3_deterministic.json index 9abf2eae..3bb99a3a 100644 --- a/builds/prepare_builds/assets/dim3_deterministic.json +++ b/builds/prepare_builds/assets/dim3_deterministic.json @@ -9,5 +9,8 @@ "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], - "js_package_name": "rapier3d-deterministic" + "js_package_name": "rapier3d-deterministic", + "conditions_to_remove": [ + "DIM2" + ] } \ No newline at end of file diff --git a/builds/prepare_builds/assets/dim3_simd.json b/builds/prepare_builds/assets/dim3_simd.json index 29ce6de9..49960000 100644 --- a/builds/prepare_builds/assets/dim3_simd.json +++ b/builds/prepare_builds/assets/dim3_simd.json @@ -11,5 +11,8 @@ "additional_wasm_opt_flags": [ "--enable-simd" ], - "js_package_name": "rapier3d-simd" + "js_package_name": "rapier3d-simd", + "conditions_to_remove": [ + "DIM2" + ] } \ No newline at end of file diff --git a/builds/prepare_builds/assets/example_dim2_minimal.json b/builds/prepare_builds/assets/example_dim2_minimal.json index 7038625b..45516917 100644 --- a/builds/prepare_builds/assets/example_dim2_minimal.json +++ b/builds/prepare_builds/assets/example_dim2_minimal.json @@ -5,5 +5,10 @@ "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], - "js_package_name": "rapier3d-minimal" + "js_package_name": "rapier3d-minimal", + "conditions_to_remove": [ + "DIM3", + "SERDE_SERIALIZE", + "DEBUG_RENDER" + ] } \ No newline at end of file diff --git a/builds/prepare_builds/assets/example_dim3_minimal.json b/builds/prepare_builds/assets/example_dim3_minimal.json index 7038625b..a349ed5f 100644 --- a/builds/prepare_builds/assets/example_dim3_minimal.json +++ b/builds/prepare_builds/assets/example_dim3_minimal.json @@ -5,5 +5,10 @@ "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], - "js_package_name": "rapier3d-minimal" + "js_package_name": "rapier3d-minimal", + "conditions_to_remove": [ + "DIM2", + "SERDE_SERIALIZE", + "DEBUG_RENDER" + ] } \ No newline at end of file diff --git a/builds/prepare_builds/src/main.rs b/builds/prepare_builds/src/main.rs index ebe1465b..48367860 100644 --- a/builds/prepare_builds/src/main.rs +++ b/builds/prepare_builds/src/main.rs @@ -30,6 +30,8 @@ pub struct BuildValues { pub additional_rust_flags: String, pub additional_wasm_opt_flags: Vec, pub js_package_name: String, + /// To remove text blocks present in non-rust files bounded by `#if CONDITION ... #endif` + pub conditions_to_remove: Vec, } impl BuildValues { @@ -105,6 +107,7 @@ fn process_templates(build_values: &BuildValues) -> std::io::Result<()> { &build_values.additional_wasm_opt_flags, ); context.insert("js_package_name", &build_values.js_package_name); + context.insert("conditions_to_remove", &build_values.conditions_to_remove); let tera = match Tera::new(target_dir.join("**/*.tera").to_str().unwrap()) { Ok(t) => t, diff --git a/builds/prepare_builds/templates/Cargo.toml.tera b/builds/prepare_builds/templates/Cargo.toml.tera index 88d71dd7..fe0ef935 100644 --- a/builds/prepare_builds/templates/Cargo.toml.tera +++ b/builds/prepare_builds/templates/Cargo.toml.tera @@ -12,16 +12,25 @@ license = "Apache-2.0" edition = "2018" [features] -default = ["dim{{ dimension }}"] +default = ["dim{{ dimension }}", + {%- for feature in additional_features %} + "{{ feature }}", + {%- endfor %}] dim{{ dimension }} = [] debug-render = ["rapier{{ dimension }}d/debug-render", "dep:palette"] serde-serialize = ["rapier{{ dimension }}d/serde-serialize", "dep:serde", "dep:bincode"] +enhanced-determinism = ["rapier{{ dimension }}d/enhanced-determinism"] +simd-stable = ["rapier{{ dimension }}d/simd-stable"] [lib] name = "rapier_wasm{{ dimension }}d" path = "../../src/lib.rs" crate-type = ["cdylib", "rlib"] -required-features = ["dim{{ dimension }}"] +required-features = ["dim{{ dimension }}", + {%- for feature in additional_features %} + "{{ feature }}", + {%- endfor %} +] [lints] rust.unexpected_cfgs = { level = "warn", check-cfg = [ @@ -29,11 +38,7 @@ rust.unexpected_cfgs = { level = "warn", check-cfg = [ ] } [dependencies] -rapier{{ dimension }}d = { version = "0.26.1", features = [ - {%- for feature in additional_features %} - "{{ feature }}", - {%- endfor %} -] } +rapier{{ dimension }}d = { version = "0.26.1" } ref-cast = "1" wasm-bindgen = "0.2.100" js-sys = "0.3" diff --git a/builds/prepare_builds/templates/build_rust.sh.tera b/builds/prepare_builds/templates/build_rust.sh.tera index 73d450d0..38f55bff 100755 --- a/builds/prepare_builds/templates/build_rust.sh.tera +++ b/builds/prepare_builds/templates/build_rust.sh.tera @@ -6,12 +6,11 @@ cargo clean RUSTFLAGS='{{ additional_rust_flags }}' {% else -%} {%- endif -%} npx wasm-pack build -sed -i.bak 's#dimforge_rapier#@dimforge/rapier#g' pkg/package.json -sed -i.bak 's/"rapier_wasm{{ dimension }}d_bg.wasm"/"*"/g' pkg/package.json +sed -i 's#dimforge_rapier#@dimforge/rapier#g' pkg/package.json +sed -i 's/"rapier_wasm{{ dimension }}d_bg.wasm"/"*"/g' pkg/package.json ( cd pkg npm pkg delete sideEffects npm pkg set 'sideEffects[0]'="./*.js" ) -rm pkg/*.bak rm pkg/.gitignore diff --git a/builds/prepare_builds/templates/build_typescript.sh.tera b/builds/prepare_builds/templates/build_typescript.sh.tera index 4b8e813d..9598f68c 100755 --- a/builds/prepare_builds/templates/build_typescript.sh.tera +++ b/builds/prepare_builds/templates/build_typescript.sh.tera @@ -5,15 +5,10 @@ cp -r ../../src.ts/* pkg/src/. rm -f ./pkg/raw.ts echo 'export * from "./rapier_wasm{{ dimension }}d"' > pkg/src/raw.ts # See https://serverfault.com/a/137848 -find pkg/ -type f -print0 | LC_ALL=C xargs -0 sed -i.bak '\:#if DIM{% if dimension == "2" %}3{% else %}2{% endif %}:,\:#endif:d' -{% if "serde-serialize" not in additional_features -%} -find pkg/ -type f -print0 | LC_ALL=C xargs -0 sed -i.bak '\:#if SERDE_SERIALIZE:,\:#endif:d' -{% endif -%} -{% if "debug-render" not in additional_features -%} -find pkg/ -type f -print0 | LC_ALL=C xargs -0 sed -i.bak '\:#if DEBUG_RENDER:,\:#endif:d' -{% endif -%} +{% for condition_to_remove in conditions_to_remove %} +find pkg/ -type f -print0 | LC_ALL=C xargs -0 sed -i '\:#if {{condition_to_remove}}:,\:#endif:d' +{% endfor %} npx tsc # NOTE: we keep the typescripts files into the NPM package for source mapping: see #3 -sed -i.bak 's/"module": "rapier_wasm{{ dimension }}d.js"/"module": "rapier.js"/g' pkg/package.json -sed -i.bak 's/"types": "rapier_wasm{{ dimension }}d.d.ts"/"types": "rapier.d.ts"/g' pkg/package.json -find pkg/ -type f -name '*.bak' | xargs rm +sed -i 's/"module": "rapier_wasm{{ dimension }}d.js"/"module": "rapier.js"/g' pkg/package.json +sed -i 's/"types": "rapier_wasm{{ dimension }}d.d.ts"/"types": "rapier.d.ts"/g' pkg/package.json diff --git a/rapier-compat/build-rust.sh b/rapier-compat/build-rust.sh index 1fb4f2fb..c41470eb 100755 --- a/rapier-compat/build-rust.sh +++ b/rapier-compat/build-rust.sh @@ -2,18 +2,10 @@ help() { - printf "Usage: %s: [-c CONFIG_NAME]\n" $0 + printf "Usage: %s: CONFIG_NAME\n" $0 } -while getopts :c: conf_name -do - case $conf_name in - c) - config_file_name="$OPTARG" - ;; - ?) help ; exit 1;; - esac -done +config_file_name="$1" if [[ -z "$config_file_name" ]]; then help; exit 2; diff --git a/rapier-compat/build_conf.sh b/rapier-compat/build_conf.sh new file mode 100755 index 00000000..0760f422 --- /dev/null +++ b/rapier-compat/build_conf.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -e + +help() +{ + printf "Usage: %s: CONFIG_FILE_NAME ...\n" $0 +} + +if [[ -z "$@" ]]; then + help; exit 2; +fi + +for config_file_name in "$@" +do + + ./build-rust.sh $config_file_name + ./gen_src.sh $config_file_name + npm run my_rollup + +done diff --git a/rapier-compat/fix_raw_file.sh b/rapier-compat/fix_raw_file.sh deleted file mode 100644 index 66f8bfaf..00000000 --- a/rapier-compat/fix_raw_file.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -for feature in \ -2d 2d-deterministic 2d-simd \ -3d 3d-deterministic 3d-simd -do - -echo 'export * from "'"./rapier_wasm$feature"'"' > builds/${feature}/pkg/raw.d.ts -echo 'export * from "'"./rapier_wasm$feature"'"' > builds/${feature}/pkg/raw.d.ts - -done; \ No newline at end of file diff --git a/rapier-compat/gen_src.sh b/rapier-compat/gen_src.sh index 04c3adaf..4a200046 100755 --- a/rapier-compat/gen_src.sh +++ b/rapier-compat/gen_src.sh @@ -1,60 +1,58 @@ +#!/bin/sh + # Copy source and remove #if sections - similar to script in ../rapierXd set -e -gen_js() { - DIM=$1 - GENOUT="./gen${DIM}" +help() +{ + printf "Usage: %s: CONFIG_FILE_NAME\n" $0 +} - # Make output directories - rm -rf ${GENOUT} - mkdir -p ${GENOUT} +config_file_name=$1 - # Copy common sources - cp -r ../src.ts/* $GENOUT +if [ -z "$config_file_name" ]; then + help; exit 2; +fi - # Copy compat mode override sources - rm -f "${GENOUT}/raw.ts" "${GENOUT}/init.ts" - cp -r ./src${DIM}/* $GENOUT -} +config_file_path="../builds/prepare_builds/assets/$config_file_name.json" -gen_js "2d" -gen_js "3d" +js_package_name=`node -pe 'JSON.parse(process.argv[1]).js_package_name' "$(cat ${config_file_path})"` +dimension=`node -pe 'JSON.parse(process.argv[1]).dim' "$(cat ${config_file_path})"` +conditions_to_remove=`node -pe 'JSON.parse(process.argv[1]).conditions_to_remove.join(" ")' "$(cat ${config_file_path})"` -# See https://serverfault.com/a/137848 -find gen2d/ -type f -print0 | LC_ALL=C xargs -0 sed -i.bak '\:#if DIM3:,\:#endif:d' -find gen3d/ -type f -print0 | LC_ALL=C xargs -0 sed -i.bak '\:#if DIM2:,\:#endif:d' +DIM="${dimension}d" +GENOUT="./builds/${js_package_name}/gen${DIM}" -# Clean up backup files. -find gen2d/ -type f -name '*.bak' | xargs rm -find gen3d/ -type f -name '*.bak' | xargs rm +# Make output directories +rm -rf ${GENOUT} +mkdir -p ${GENOUT} -for features_set in \ -"2" "2 deterministic" "2 simd" \ -"3" "3 deterministic" "3 simd" "3" -do +# Copy common sources +cp -r ../src.ts/* $GENOUT - set -- $features_set # Convert the "tuple" into the param args $1 $2... - dimension=$1 - if [ -z "$2" ]; then - feature="${1}d"; - else - feature="${1}d-${2}"; - fi - - rm -rf ./builds/${feature}/pkg/ - mkdir -p ./builds/${feature}/pkg/ +# Copy compat mode override sources +rm -f "${GENOUT}/raw.ts" "${GENOUT}/init.ts" +cp -r ./src${DIM}/* $GENOUT - cp ./builds/${feature}/wasm-build/rapier_wasm* ./builds/${feature}/pkg/ - cp -r ./gen${dimension}d ./builds/${feature}/ +echo ${conditions_to_remove} - # copy tsconfig, as they contain paths - cp ./tsconfig.common.json ./tsconfig.json ./builds/${feature}/ - cp ./tsconfig.pkg${dimension}d.json ./builds/${feature}/tsconfig.pkg.json +for condition_to_remove in "${conditions_to_remove}" ; do + # See https://serverfault.com/a/137848 + echo "find ${GENOUT} -type f -print0 | LC_ALL=C xargs -0 sed -i \"\\:#if ${condition_to_remove}:,\\:#endif:d\"" + find ${GENOUT} -type f -print0 | LC_ALL=C xargs -0 sed -i "\\:#if ${condition_to_remove}:,\\:#endif:d" +done - # "import.meta" causes Babel to choke, but the code path is never taken so just remove it. - sed -i.bak 's/import.meta.url/""/g' ./builds/${feature}/pkg/rapier_wasm${dimension}d.js +rm -rf ./builds/${js_package_name}/pkg/ +mkdir -p ./builds/${js_package_name}/pkg/ - # Clean up backup files. - find ./builds/${feature}/pkg/ -type f -name '*.bak' | xargs rm +cp ./builds/${js_package_name}/wasm-build/rapier_wasm* ./builds/${js_package_name}/pkg/ -done +# fix raw file +echo 'export * from "'"./rapier_wasm$DIM"'"' > builds/${js_package_name}/pkg/raw.d.ts + +# copy tsconfig, as they contain paths +cp ./tsconfig.common.json ./tsconfig.json ./builds/${js_package_name}/ +cp ./tsconfig.pkg${dimension}d.json ./builds/${js_package_name}/tsconfig.pkg.json + +# "import.meta" causes Babel to choke, but the code path is never taken so just remove it. +sed -i 's/import.meta.url/""/g' ./builds/${js_package_name}/pkg/rapier_wasm${dimension}d.js diff --git a/rapier-compat/package-lock.json b/rapier-compat/package-lock.json index 22b6f023..d279a40a 100644 --- a/rapier-compat/package-lock.json +++ b/rapier-compat/package-lock.json @@ -16,7 +16,7 @@ "@types/jest": "^29.2.1", "jest": "^29.2.2", "rimraf": "^3.0.2", - "rollup": "^3.2.5", + "rollup": "^3.29.5", "rollup-plugin-base64": "^1.0.1", "rollup-plugin-copy": "^3.4.0", "rollup-plugin-filesize": "^9.1.2", @@ -5096,10 +5096,11 @@ } }, "node_modules/rollup": { - "version": "3.2.5", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.2.5.tgz", - "integrity": "sha512-/Ha7HhVVofduy+RKWOQJrxe4Qb3xyZo+chcpYiD8SoQa4AG7llhupUtyfKSSrdBM2mWJjhM8wZwmbY23NmlIYw==", + "version": "3.29.5", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.29.5.tgz", + "integrity": "sha512-GVsDdsbJzzy4S/v3dqWPJ7EfvZJfCHiDqe80IyrF59LYuP+e6U1LJoUqeuqRbwAWoMNoXivMNeNAOf5E22VA1w==", "dev": true, + "license": "MIT", "bin": { "rollup": "dist/bin/rollup" }, @@ -9867,9 +9868,9 @@ } }, "rollup": { - "version": "3.2.5", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.2.5.tgz", - "integrity": "sha512-/Ha7HhVVofduy+RKWOQJrxe4Qb3xyZo+chcpYiD8SoQa4AG7llhupUtyfKSSrdBM2mWJjhM8wZwmbY23NmlIYw==", + "version": "3.29.5", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.29.5.tgz", + "integrity": "sha512-GVsDdsbJzzy4S/v3dqWPJ7EfvZJfCHiDqe80IyrF59LYuP+e6U1LJoUqeuqRbwAWoMNoXivMNeNAOf5E22VA1w==", "dev": true, "requires": { "fsevents": "~2.3.2" diff --git a/rapier-compat/package.json b/rapier-compat/package.json index b98fa1de..dc56534e 100644 --- a/rapier-compat/package.json +++ b/rapier-compat/package.json @@ -4,22 +4,20 @@ "private": true, "scripts": { "prepare-all-projects": "../builds/prepare_builds/prepare_all_projects.sh", - "build-rust-2d-non-deterministic": "./build-rust.sh -c dim2", - "build-rust-2d-deterministic": "./build-rust.sh -c dim2_deterministic", - "build-rust-2d-simd": "./build-rust.sh -c dim2_simd", - "build-rust-2d-all": "npm run build-rust-2d-non-deterministic && npm run build-rust-2d-deterministic && npm run build-rust-2d-simd", - "build-rust-3d-non-deterministic": "./build-rust.sh -c dim3", - "build-rust-3d-deterministic": "./build-rust.sh -c dim3_deterministic", - "build-rust-3d-simd": "./build-rust.sh -c dim3_simd", - "build-rust-3d-all": "npm run build-rust-3d-non-deterministic && npm run build-rust-3d-deterministic && npm run build-rust-3d-simd", - "build-rust-all": "npm run build-rust-2d-all && npm run build-rust-3d-all", - "build-genjs": "sh ./gen_src.sh", - "build-js": "rollup --config rollup.config.js --bundleConfigAsCjs", + "build2d-non-deterministic": "./build_conf.sh dim2", + "build-2d-deterministic": "./build_conf.sh dim2_deterministic", + "build-2d-simd": "./build_conf.sh dim2_simd", + "build-2d-all": "npm run build-2d-non-deterministic && npm run build-2d-deterministic && npm run build-2d-simd", + "build-3d-non-deterministic": "./build_conf.sh dim3 && ./gen_src.sh dim3", + "build-3d-deterministic": "./build_conf.sh dim3_deterministic && ./gen_src.sh dim3_deterministic", + "build-3d-simd": "./build_conf.sh dim3_simd", + "build-3d-all": "npm run build-3d-non-deterministic && npm run build-3d-deterministic && npm run build-3d-simd", + "build-all": "npm run build-2d-all && npm run build-3d-all", "fix-raw-file": "sh ./fix_raw_file.sh", - "build": "npm run clean && npm run build-rust-all && npm run build-genjs && npm run build-js && npm run fix-raw-file", - "clean": "rimraf gen2d gen3d builds", + "build": "npm run clean && npm run build-rust-all && npm run build-genjs && npm run fix-raw-file", + "clean": "cargo clean && rimraf gen2d gen3d builds", "test": "jest --detectOpenHandles", - "all": "npm run build" + "my_rollup": "rollup --config rollup.config.js --bundleConfigAsCjs --environment BUILD_CONFIG_NAME:dim2" }, "dependencies": { "base64-js": "^1.5.1" @@ -27,12 +25,12 @@ "devDependencies": { "@rollup/plugin-commonjs": "^23.0.2", "@rollup/plugin-node-resolve": "^15.0.1", - "@rollup/plugin-typescript": "^9.0.2", "@rollup/plugin-terser": "0.1.0", + "@rollup/plugin-typescript": "^9.0.2", "@types/jest": "^29.2.1", "jest": "^29.2.2", "rimraf": "^3.0.2", - "rollup": "^3.2.5", + "rollup": "^3.29.5", "rollup-plugin-base64": "^1.0.1", "rollup-plugin-copy": "^3.4.0", "rollup-plugin-filesize": "^9.1.2", diff --git a/rapier-compat/rollup.config.js b/rapier-compat/rollup.config.js index 60c12eb6..f5dd34d5 100644 --- a/rapier-compat/rollup.config.js +++ b/rapier-compat/rollup.config.js @@ -8,17 +8,17 @@ import copy from "rollup-plugin-copy"; import filesize from "rollup-plugin-filesize"; import * as fs from 'fs'; -const config = (dim, features_postfix) => ({ - input: `builds/${features_postfix}/gen${dim}/rapier.ts`, +const config = (dim, js_package_name) => ({ + input: `builds/${js_package_name}/gen${dim}/rapier.ts`, output: [ { - file: `builds/${features_postfix}/pkg/rapier.es.js`, + file: `builds/${js_package_name}/pkg/rapier.es.js`, format: "es", sourcemap: true, exports: "named", }, { - file: `builds/${features_postfix}/pkg/rapier.cjs.js`, + file: `builds/${js_package_name}/pkg/rapier.cjs.js`, format: "cjs", sourcemap: true, exports: "named", @@ -28,11 +28,11 @@ const config = (dim, features_postfix) => ({ copy({ targets: [ { - src: `builds/${features_postfix}/wasm-build/package.json`, - dest: `builds/${features_postfix}/pkg/`, + src: `builds/${js_package_name}/wasm-build/package.json`, + dest: `builds/${js_package_name}/pkg/`, transform(content) { let config = JSON.parse(content.toString()); - config.name = `@dimforge/rapier${features_postfix}-compat`; + config.name = `@dimforge/${js_package_name}`; config.description += " Compatibility package with inlined webassembly as base64."; config.types = "rapier.d.ts"; @@ -44,12 +44,12 @@ const config = (dim, features_postfix) => ({ }, }, { - src: `../rapier${features_postfix}/LICENSE`, - dest: `builds/${features_postfix}/pkg`, + src: `../${js_package_name}/LICENSE`, + dest: `builds/${js_package_name}/pkg`, }, { - src: `../rapier${features_postfix}/README.md`, - dest: `builds/${features_postfix}/pkg`, + src: `../${js_package_name}/README.md`, + dest: `builds/${js_package_name}/pkg`, }, ], }), @@ -60,7 +60,7 @@ const config = (dim, features_postfix) => ({ typescript({ tsconfig: path.resolve( __dirname, - `builds/${features_postfix}/tsconfig.pkg.json`, + `builds/${js_package_name}/tsconfig.pkg.json`, ), sourceMap: true, inlineSources: true, @@ -69,17 +69,11 @@ const config = (dim, features_postfix) => ({ ], }); -const conf = JSON.parse(fs.readFileSync('../builds/prepare_builds/assets/dim2.json')); +const conf = JSON.parse(fs.readFileSync('../builds/prepare_builds/assets/' + process.env.BUILD_CONFIG_NAME + '.json')); + +//console.log(conf); -console.log(conf); -/* export default [ - config("2d", "2d"), - config("2d", "2d-deterministic"), - config("2d", "2d-simd"), - config("3d", "3d"), - config("3d", "3d-deterministic"), - config("3d", "3d-simd"), -]; -*/ \ No newline at end of file + config("" + conf.dim + "d", conf.js_package_name), +]; \ No newline at end of file diff --git a/rapier-compat/tsconfig.pkg3d.json b/rapier-compat/tsconfig.pkg3d.json index 3d7323e8..05776bc4 100644 --- a/rapier-compat/tsconfig.pkg3d.json +++ b/rapier-compat/tsconfig.pkg3d.json @@ -2,7 +2,9 @@ "extends": "./tsconfig.common.json", "compilerOptions": { "rootDir": "./gen3d", - "outDir": "." + "outDir": "./3d" }, - "files": ["./gen3d/rapier.ts"] -} + "files": [ + "./gen3d/rapier.ts" + ] +} \ No newline at end of file From 4f6daf725eb6423da31979aa4aa1eff1a30fab73 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Thu, 5 Jun 2025 10:27:09 +0200 Subject: [PATCH 04/12] no more hardcoded rollup --- builds/prepare_builds/src/main.rs | 2 +- rapier-compat/build_conf.sh | 2 +- rapier-compat/gen_src.sh | 2 -- rapier-compat/package.json | 18 ++++++------------ rapier-compat/rollup.config.js | 2 -- 5 files changed, 8 insertions(+), 18 deletions(-) diff --git a/builds/prepare_builds/src/main.rs b/builds/prepare_builds/src/main.rs index 48367860..e37644fe 100644 --- a/builds/prepare_builds/src/main.rs +++ b/builds/prepare_builds/src/main.rs @@ -23,7 +23,7 @@ pub struct Args { pub struct BuildValues { /// Only the number of dimensions (1 or 2), as sometimes it will be prefixed by "dim" and sometimes post-fixed by "d". pub dim: String, - /// real name of the additional features to enable in the project + /// Rust name of the additional features to enable in the project, they should correspond to features from Cargo.toml(.tera). pub feature_set: Vec, pub target_dir: PathBuf, pub template_dir: PathBuf, diff --git a/rapier-compat/build_conf.sh b/rapier-compat/build_conf.sh index 0760f422..7c31d058 100755 --- a/rapier-compat/build_conf.sh +++ b/rapier-compat/build_conf.sh @@ -16,6 +16,6 @@ do ./build-rust.sh $config_file_name ./gen_src.sh $config_file_name - npm run my_rollup + npm run rollup -- --config rollup.config.js --bundleConfigAsCjs --environment BUILD_CONFIG_NAME:${config_file_name} done diff --git a/rapier-compat/gen_src.sh b/rapier-compat/gen_src.sh index 4a200046..fe76f7ff 100755 --- a/rapier-compat/gen_src.sh +++ b/rapier-compat/gen_src.sh @@ -34,8 +34,6 @@ cp -r ../src.ts/* $GENOUT rm -f "${GENOUT}/raw.ts" "${GENOUT}/init.ts" cp -r ./src${DIM}/* $GENOUT -echo ${conditions_to_remove} - for condition_to_remove in "${conditions_to_remove}" ; do # See https://serverfault.com/a/137848 echo "find ${GENOUT} -type f -print0 | LC_ALL=C xargs -0 sed -i \"\\:#if ${condition_to_remove}:,\\:#endif:d\"" diff --git a/rapier-compat/package.json b/rapier-compat/package.json index dc56534e..4cd19543 100644 --- a/rapier-compat/package.json +++ b/rapier-compat/package.json @@ -4,20 +4,14 @@ "private": true, "scripts": { "prepare-all-projects": "../builds/prepare_builds/prepare_all_projects.sh", - "build2d-non-deterministic": "./build_conf.sh dim2", - "build-2d-deterministic": "./build_conf.sh dim2_deterministic", - "build-2d-simd": "./build_conf.sh dim2_simd", - "build-2d-all": "npm run build-2d-non-deterministic && npm run build-2d-deterministic && npm run build-2d-simd", - "build-3d-non-deterministic": "./build_conf.sh dim3 && ./gen_src.sh dim3", - "build-3d-deterministic": "./build_conf.sh dim3_deterministic && ./gen_src.sh dim3_deterministic", - "build-3d-simd": "./build_conf.sh dim3_simd", - "build-3d-all": "npm run build-3d-non-deterministic && npm run build-3d-deterministic && npm run build-3d-simd", - "build-all": "npm run build-2d-all && npm run build-3d-all", + "build-2d-all": "./build_conf.sh dim2 dim2_deterministic dim2_simd", + "build-3d-all": "./build_conf.sh dim3 dim3_deterministic dim3_simd", + "build-all": "./build_conf.sh dim2 dim3 dim2_deterministic dim3_deterministic dim2_simd dim3_simd", "fix-raw-file": "sh ./fix_raw_file.sh", - "build": "npm run clean && npm run build-rust-all && npm run build-genjs && npm run fix-raw-file", - "clean": "cargo clean && rimraf gen2d gen3d builds", + "build": "npm run clean && npm run build-all", + "clean": "cargo clean && rimraf builds", "test": "jest --detectOpenHandles", - "my_rollup": "rollup --config rollup.config.js --bundleConfigAsCjs --environment BUILD_CONFIG_NAME:dim2" + "rollup": "rollup" }, "dependencies": { "base64-js": "^1.5.1" diff --git a/rapier-compat/rollup.config.js b/rapier-compat/rollup.config.js index f5dd34d5..0a40c6a6 100644 --- a/rapier-compat/rollup.config.js +++ b/rapier-compat/rollup.config.js @@ -71,8 +71,6 @@ const config = (dim, js_package_name) => ({ const conf = JSON.parse(fs.readFileSync('../builds/prepare_builds/assets/' + process.env.BUILD_CONFIG_NAME + '.json')); -//console.log(conf); - export default [ config("" + conf.dim + "d", conf.js_package_name), From f4cd01e6afa89a9684a2fe59149f47955fb0ab82 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Thu, 5 Jun 2025 10:56:54 +0200 Subject: [PATCH 05/12] reinstate bak files as they are mandatory on mac --- builds/prepare_builds/templates/build_rust.sh.tera | 5 +++-- builds/prepare_builds/templates/build_typescript.sh.tera | 7 ++++--- rapier-compat/gen_src.sh | 9 ++++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/builds/prepare_builds/templates/build_rust.sh.tera b/builds/prepare_builds/templates/build_rust.sh.tera index 38f55bff..73d450d0 100755 --- a/builds/prepare_builds/templates/build_rust.sh.tera +++ b/builds/prepare_builds/templates/build_rust.sh.tera @@ -6,11 +6,12 @@ cargo clean RUSTFLAGS='{{ additional_rust_flags }}' {% else -%} {%- endif -%} npx wasm-pack build -sed -i 's#dimforge_rapier#@dimforge/rapier#g' pkg/package.json -sed -i 's/"rapier_wasm{{ dimension }}d_bg.wasm"/"*"/g' pkg/package.json +sed -i.bak 's#dimforge_rapier#@dimforge/rapier#g' pkg/package.json +sed -i.bak 's/"rapier_wasm{{ dimension }}d_bg.wasm"/"*"/g' pkg/package.json ( cd pkg npm pkg delete sideEffects npm pkg set 'sideEffects[0]'="./*.js" ) +rm pkg/*.bak rm pkg/.gitignore diff --git a/builds/prepare_builds/templates/build_typescript.sh.tera b/builds/prepare_builds/templates/build_typescript.sh.tera index 9598f68c..9eea9e2c 100755 --- a/builds/prepare_builds/templates/build_typescript.sh.tera +++ b/builds/prepare_builds/templates/build_typescript.sh.tera @@ -6,9 +6,10 @@ rm -f ./pkg/raw.ts echo 'export * from "./rapier_wasm{{ dimension }}d"' > pkg/src/raw.ts # See https://serverfault.com/a/137848 {% for condition_to_remove in conditions_to_remove %} -find pkg/ -type f -print0 | LC_ALL=C xargs -0 sed -i '\:#if {{condition_to_remove}}:,\:#endif:d' +find pkg/ -type f -print0 | LC_ALL=C xargs -0 sed -i.bak '\:#if {{condition_to_remove}}:,\:#endif:d' {% endfor %} npx tsc # NOTE: we keep the typescripts files into the NPM package for source mapping: see #3 -sed -i 's/"module": "rapier_wasm{{ dimension }}d.js"/"module": "rapier.js"/g' pkg/package.json -sed -i 's/"types": "rapier_wasm{{ dimension }}d.d.ts"/"types": "rapier.d.ts"/g' pkg/package.json +sed -i.bak 's/"module": "rapier_wasm{{ dimension }}d.js"/"module": "rapier.js"/g' pkg/package.json +sed -i.bak 's/"types": "rapier_wasm{{ dimension }}d.d.ts"/"types": "rapier.d.ts"/g' pkg/package.json +find pkg/ -type f -name '*.bak' | xargs rm diff --git a/rapier-compat/gen_src.sh b/rapier-compat/gen_src.sh index fe76f7ff..a9878a7a 100755 --- a/rapier-compat/gen_src.sh +++ b/rapier-compat/gen_src.sh @@ -36,8 +36,8 @@ cp -r ./src${DIM}/* $GENOUT for condition_to_remove in "${conditions_to_remove}" ; do # See https://serverfault.com/a/137848 - echo "find ${GENOUT} -type f -print0 | LC_ALL=C xargs -0 sed -i \"\\:#if ${condition_to_remove}:,\\:#endif:d\"" - find ${GENOUT} -type f -print0 | LC_ALL=C xargs -0 sed -i "\\:#if ${condition_to_remove}:,\\:#endif:d" + echo "find ${GENOUT} -type f -print0 | LC_ALL=C xargs -0 sed -i.bak \"\\:#if ${condition_to_remove}:,\\:#endif:d\"" + find ${GENOUT} -type f -print0 | LC_ALL=C xargs -0 sed -i.bak "\\:#if ${condition_to_remove}:,\\:#endif:d" done rm -rf ./builds/${js_package_name}/pkg/ @@ -53,4 +53,7 @@ cp ./tsconfig.common.json ./tsconfig.json ./builds/${js_package_name}/ cp ./tsconfig.pkg${dimension}d.json ./builds/${js_package_name}/tsconfig.pkg.json # "import.meta" causes Babel to choke, but the code path is never taken so just remove it. -sed -i 's/import.meta.url/""/g' ./builds/${js_package_name}/pkg/rapier_wasm${dimension}d.js +sed -i.bak 's/import.meta.url/""/g' ./builds/${js_package_name}/pkg/rapier_wasm${dimension}d.js + +# Clean up backup files. +find ./builds/${js_package_name}/ -type f -name '*.bak' | xargs rm \ No newline at end of file From a56bb97a8e574ee5da77e3d56a122117128f19bd Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Thu, 5 Jun 2025 10:57:57 +0200 Subject: [PATCH 06/12] run prettifier --- builds/prepare_builds/assets/dim2.json | 11 +++----- .../assets/dim2_deterministic.json | 12 +++------ builds/prepare_builds/assets/dim2_simd.json | 26 +++++++------------ builds/prepare_builds/assets/dim3.json | 11 +++----- .../assets/dim3_deterministic.json | 12 +++------ builds/prepare_builds/assets/dim3_simd.json | 16 +++--------- .../assets/example_dim2_minimal.json | 8 ++---- .../assets/example_dim3_minimal.json | 8 ++---- rapier-compat/package.json | 2 +- rapier-compat/rollup.config.js | 15 ++++++----- rapier-compat/tsconfig.pkg3d.json | 6 ++--- src.ts/pipeline/world.ts | 2 +- 12 files changed, 42 insertions(+), 87 deletions(-) diff --git a/builds/prepare_builds/assets/dim2.json b/builds/prepare_builds/assets/dim2.json index 09b3ec15..4a3ab8ca 100644 --- a/builds/prepare_builds/assets/dim2.json +++ b/builds/prepare_builds/assets/dim2.json @@ -1,15 +1,10 @@ { "dim": "2", - "feature_set": [ - "serde-serialize", - "debug-render" - ], + "feature_set": ["serde-serialize", "debug-render"], "target_dir": "../rapier2d/", "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], "js_package_name": "rapier2d", - "conditions_to_remove": [ - "DIM3" - ] -} \ No newline at end of file + "conditions_to_remove": ["DIM3"] +} diff --git a/builds/prepare_builds/assets/dim2_deterministic.json b/builds/prepare_builds/assets/dim2_deterministic.json index 20c08baf..5b71b8aa 100644 --- a/builds/prepare_builds/assets/dim2_deterministic.json +++ b/builds/prepare_builds/assets/dim2_deterministic.json @@ -1,16 +1,10 @@ { "dim": "2", - "feature_set": [ - "serde-serialize", - "debug-render", - "enhanced-determinism" - ], + "feature_set": ["serde-serialize", "debug-render", "enhanced-determinism"], "target_dir": "../rapier2d-deterministic", "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], "js_package_name": "rapier2d-deterministic", - "conditions_to_remove": [ - "DIM3" - ] -} \ No newline at end of file + "conditions_to_remove": ["DIM3"] +} diff --git a/builds/prepare_builds/assets/dim2_simd.json b/builds/prepare_builds/assets/dim2_simd.json index 5a0d9e2a..e1ff575d 100644 --- a/builds/prepare_builds/assets/dim2_simd.json +++ b/builds/prepare_builds/assets/dim2_simd.json @@ -1,18 +1,10 @@ { - "dim": "2", - "feature_set": [ - "serde-serialize", - "debug-render", - "simd-stable" - ], - "target_dir": "../rapier2d-simd", - "template_dir": "./templates/", - "additional_rust_flags": "-C target-feature=+simd128", - "additional_wasm_opt_flags": [ - "--enable-simd" - ], - "js_package_name": "rapier2d-simd", - "conditions_to_remove": [ - "DIM3" - ] -} \ No newline at end of file + "dim": "2", + "feature_set": ["serde-serialize", "debug-render", "simd-stable"], + "target_dir": "../rapier2d-simd", + "template_dir": "./templates/", + "additional_rust_flags": "-C target-feature=+simd128", + "additional_wasm_opt_flags": ["--enable-simd"], + "js_package_name": "rapier2d-simd", + "conditions_to_remove": ["DIM3"] +} diff --git a/builds/prepare_builds/assets/dim3.json b/builds/prepare_builds/assets/dim3.json index b1887410..cdbcf637 100644 --- a/builds/prepare_builds/assets/dim3.json +++ b/builds/prepare_builds/assets/dim3.json @@ -1,15 +1,10 @@ { "dim": "3", - "feature_set": [ - "serde-serialize", - "debug-render" - ], + "feature_set": ["serde-serialize", "debug-render"], "target_dir": "../rapier3d/", "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], "js_package_name": "rapier3d", - "conditions_to_remove": [ - "DIM2" - ] -} \ No newline at end of file + "conditions_to_remove": ["DIM2"] +} diff --git a/builds/prepare_builds/assets/dim3_deterministic.json b/builds/prepare_builds/assets/dim3_deterministic.json index 3bb99a3a..addba523 100644 --- a/builds/prepare_builds/assets/dim3_deterministic.json +++ b/builds/prepare_builds/assets/dim3_deterministic.json @@ -1,16 +1,10 @@ { "dim": "3", - "feature_set": [ - "serde-serialize", - "debug-render", - "enhanced-determinism" - ], + "feature_set": ["serde-serialize", "debug-render", "enhanced-determinism"], "target_dir": "../rapier3d-deterministic", "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], "js_package_name": "rapier3d-deterministic", - "conditions_to_remove": [ - "DIM2" - ] -} \ No newline at end of file + "conditions_to_remove": ["DIM2"] +} diff --git a/builds/prepare_builds/assets/dim3_simd.json b/builds/prepare_builds/assets/dim3_simd.json index 49960000..038a200c 100644 --- a/builds/prepare_builds/assets/dim3_simd.json +++ b/builds/prepare_builds/assets/dim3_simd.json @@ -1,18 +1,10 @@ { "dim": "3", - "feature_set": [ - "serde-serialize", - "debug-render", - "simd-stable" - ], + "feature_set": ["serde-serialize", "debug-render", "simd-stable"], "target_dir": "../rapier3d-simd", "template_dir": "./templates/", "additional_rust_flags": "-C target-feature=+simd128", - "additional_wasm_opt_flags": [ - "--enable-simd" - ], + "additional_wasm_opt_flags": ["--enable-simd"], "js_package_name": "rapier3d-simd", - "conditions_to_remove": [ - "DIM2" - ] -} \ No newline at end of file + "conditions_to_remove": ["DIM2"] +} diff --git a/builds/prepare_builds/assets/example_dim2_minimal.json b/builds/prepare_builds/assets/example_dim2_minimal.json index 45516917..75514e2e 100644 --- a/builds/prepare_builds/assets/example_dim2_minimal.json +++ b/builds/prepare_builds/assets/example_dim2_minimal.json @@ -6,9 +6,5 @@ "additional_rust_flags": "", "additional_wasm_opt_flags": [], "js_package_name": "rapier3d-minimal", - "conditions_to_remove": [ - "DIM3", - "SERDE_SERIALIZE", - "DEBUG_RENDER" - ] -} \ No newline at end of file + "conditions_to_remove": ["DIM3", "SERDE_SERIALIZE", "DEBUG_RENDER"] +} diff --git a/builds/prepare_builds/assets/example_dim3_minimal.json b/builds/prepare_builds/assets/example_dim3_minimal.json index a349ed5f..0fd8be41 100644 --- a/builds/prepare_builds/assets/example_dim3_minimal.json +++ b/builds/prepare_builds/assets/example_dim3_minimal.json @@ -6,9 +6,5 @@ "additional_rust_flags": "", "additional_wasm_opt_flags": [], "js_package_name": "rapier3d-minimal", - "conditions_to_remove": [ - "DIM2", - "SERDE_SERIALIZE", - "DEBUG_RENDER" - ] -} \ No newline at end of file + "conditions_to_remove": ["DIM2", "SERDE_SERIALIZE", "DEBUG_RENDER"] +} diff --git a/rapier-compat/package.json b/rapier-compat/package.json index 4cd19543..bcdc73b8 100644 --- a/rapier-compat/package.json +++ b/rapier-compat/package.json @@ -49,4 +49,4 @@ "js" ] } -} \ No newline at end of file +} diff --git a/rapier-compat/rollup.config.js b/rapier-compat/rollup.config.js index 0a40c6a6..d85c4712 100644 --- a/rapier-compat/rollup.config.js +++ b/rapier-compat/rollup.config.js @@ -6,7 +6,7 @@ import path from "path"; import {base64} from "rollup-plugin-base64"; import copy from "rollup-plugin-copy"; import filesize from "rollup-plugin-filesize"; -import * as fs from 'fs'; +import * as fs from "fs"; const config = (dim, js_package_name) => ({ input: `builds/${js_package_name}/gen${dim}/rapier.ts`, @@ -69,9 +69,12 @@ const config = (dim, js_package_name) => ({ ], }); -const conf = JSON.parse(fs.readFileSync('../builds/prepare_builds/assets/' + process.env.BUILD_CONFIG_NAME + '.json')); +const conf = JSON.parse( + fs.readFileSync( + "../builds/prepare_builds/assets/" + + process.env.BUILD_CONFIG_NAME + + ".json", + ), +); - -export default [ - config("" + conf.dim + "d", conf.js_package_name), -]; \ No newline at end of file +export default [config("" + conf.dim + "d", conf.js_package_name)]; diff --git a/rapier-compat/tsconfig.pkg3d.json b/rapier-compat/tsconfig.pkg3d.json index 05776bc4..79b6b380 100644 --- a/rapier-compat/tsconfig.pkg3d.json +++ b/rapier-compat/tsconfig.pkg3d.json @@ -4,7 +4,5 @@ "rootDir": "./gen3d", "outDir": "./3d" }, - "files": [ - "./gen3d/rapier.ts" - ] -} \ No newline at end of file + "files": ["./gen3d/rapier.ts"] +} diff --git a/src.ts/pipeline/world.ts b/src.ts/pipeline/world.ts index 5292769f..825a465e 100644 --- a/src.ts/pipeline/world.ts +++ b/src.ts/pipeline/world.ts @@ -259,7 +259,7 @@ export class World { ); } - /** + /** * Creates a new physics world from a snapshot. * * This new physics world will be an identical copy of the snapshoted physics world. From 3be0284fbabe969148139e2085d01448b8f29cbd Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Thu, 5 Jun 2025 11:12:53 +0200 Subject: [PATCH 07/12] fix compat path (test, ci, readme) --- .github/workflows/main.yml | 4 ++-- README.md | 2 +- rapier-compat/tests/World2d.test.ts | 2 +- rapier-compat/tests/World3d.test.ts | 2 +- rapier-compat/tests/math2d.test.ts | 2 +- rapier-compat/tests/math3d.test.ts | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c7977f5e..395e02f8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -114,12 +114,12 @@ jobs: # Check simd for compat builds - name: Check 2d simd compat build run: | - if ! wasm-objdump -d rapier-compat/builds/2d-simd/pkg/rapier_wasm2d_bg.wasm | grep :\\sfd ; then + if ! wasm-objdump -d rapier-compat/builds/rapier2d-simd/pkg/rapier_wasm2d_bg.wasm | grep :\\sfd ; then >&2 echo "ERROR: 2d simd compat build does not include simd opcode prefix." && exit 1; fi - name: Check 3d simd compat build run: | - if ! wasm-objdump -d rapier-compat/builds/3d-simd/pkg/rapier_wasm3d_bg.wasm | grep :\\sfd ; then + if ! wasm-objdump -d rapier-compat/builds/rapier3d-simd/pkg/rapier_wasm3d_bg.wasm | grep :\\sfd ; then >&2 echo "ERROR: 3d simd compat build does not include simd opcode prefix." && exit 1; fi # Upload diff --git a/README.md b/README.md index d04cc4bf..53f19b22 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Note that `prepare_all_projects.sh` only needs to be run once. It needs to be re The built packages will be in `builds/rapier2d/pkg`, `builds/rapier3d/pkg`, etc. To build the `-compat` variant of the packages, run `npm run build` in the `rapier-compat` directory. Note that this will only work if you already ran -`prepare_all_projects.sh`. The compat packages are then generated in, e.g., `rapier-compat/builds/3d/pkg`. +`prepare_all_projects.sh`. The compat packages are then generated in, e.g., `rapier-compat/builds/rapier3d/pkg`. ## Feature selection diff --git a/rapier-compat/tests/World2d.test.ts b/rapier-compat/tests/World2d.test.ts index 45a3bb72..ac6623bf 100644 --- a/rapier-compat/tests/World2d.test.ts +++ b/rapier-compat/tests/World2d.test.ts @@ -1,4 +1,4 @@ -import {init, Vector2, World} from "../builds/2d-deterministic/pkg"; +import {init, Vector2, World} from "../builds/rapier2d-deterministic/pkg"; describe("2d/World", () => { let world: World; diff --git a/rapier-compat/tests/World3d.test.ts b/rapier-compat/tests/World3d.test.ts index e0ddd546..adc1375e 100644 --- a/rapier-compat/tests/World3d.test.ts +++ b/rapier-compat/tests/World3d.test.ts @@ -1,4 +1,4 @@ -import {init, Vector3, World} from "../builds/3d-deterministic/pkg"; +import {init, Vector3, World} from "../builds/rapier3d-deterministic/pkg"; describe("3d/World", () => { let world: World; diff --git a/rapier-compat/tests/math2d.test.ts b/rapier-compat/tests/math2d.test.ts index a7560565..de1175f8 100644 --- a/rapier-compat/tests/math2d.test.ts +++ b/rapier-compat/tests/math2d.test.ts @@ -1,4 +1,4 @@ -import {Vector2, VectorOps} from "../builds/2d-deterministic/pkg"; +import {Vector2, VectorOps} from "../builds/rapier2d-deterministic/pkg"; describe("2d/math", () => { test("Vector2", () => { diff --git a/rapier-compat/tests/math3d.test.ts b/rapier-compat/tests/math3d.test.ts index 2ff194cc..0320cd66 100644 --- a/rapier-compat/tests/math3d.test.ts +++ b/rapier-compat/tests/math3d.test.ts @@ -1,4 +1,4 @@ -import {Vector3, VectorOps} from "../builds/3d-deterministic/pkg"; +import {Vector3, VectorOps} from "../builds/rapier3d-deterministic/pkg"; describe("3d/math", () => { test("Vector3", () => { From 8dc01211836a116fb1e623eb8fbf27f4b176e392 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Thu, 5 Jun 2025 12:11:03 +0200 Subject: [PATCH 08/12] add CI for minimal build --- .github/workflows/minimal.yml | 44 +++++++++++++++++++ Cargo.lock | 14 ++++++ builds/prepare_builds/README.md | 2 +- .../assets/example_dim2_minimal.json | 6 +-- .../assets/example_dim3_minimal.json | 2 +- builds/prepare_builds/build_all_projects.sh | 2 +- rapier-compat/build-rust.sh | 6 ++- rapier-compat/gen_src.sh | 2 +- 8 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/minimal.yml diff --git a/.github/workflows/minimal.yml b/.github/workflows/minimal.yml new file mode 100644 index 00000000..3a8a3154 --- /dev/null +++ b/.github/workflows/minimal.yml @@ -0,0 +1,44 @@ +name: minimal + +on: + push: + branches: [master] + pull_request: + branches: [master] + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + env: + RUSTFLAGS: -D warnings + steps: + - uses: actions/checkout@v4 + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - run: npm ci; + - name: Prepare minimal 2d build + working-directory: ./builds/prepare_builds/ + run: | + cargo run -- -c assets/example_dim2_minimal.json + - name: Build minimal 2d project + working-directory: ./builds/rapier2d-minimal + run: | + npm run build + - name: Build minimal 2d project compat + working-directory: ./rapier-compat + run: | + ./build_conf.sh example_dim2_minimal diff --git a/Cargo.lock b/Cargo.lock index 17105694..65d96c1f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -395,6 +395,20 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "dimforge_rapier2d-minimal" +version = "0.17.3" +dependencies = [ + "bincode", + "js-sys", + "nalgebra", + "palette", + "rapier2d", + "ref-cast", + "serde", + "wasm-bindgen", +] + [[package]] name = "dimforge_rapier2d-simd" version = "0.17.3" diff --git a/builds/prepare_builds/README.md b/builds/prepare_builds/README.md index 5c9dbb98..2b408e8f 100644 --- a/builds/prepare_builds/README.md +++ b/builds/prepare_builds/README.md @@ -6,7 +6,7 @@ It uses clap so you can pass `-h` to get more info about its parameters. ## usage -In this directory: `cargo run -- -c assets/dim2.ron`. +In this directory: `cargo run -- -c assets/dim2.json`. The configuration file contains relative links which are not made canonical so the call location is important. Or use provided scripts: `./builds/prepare_builds/prepare_all_projects.sh && ./builds/prepare_builds/build_all_projects.sh` diff --git a/builds/prepare_builds/assets/example_dim2_minimal.json b/builds/prepare_builds/assets/example_dim2_minimal.json index 75514e2e..f6dd096d 100644 --- a/builds/prepare_builds/assets/example_dim2_minimal.json +++ b/builds/prepare_builds/assets/example_dim2_minimal.json @@ -1,10 +1,10 @@ { - "dim": "3", + "dim": "2", "feature_set": [], - "target_dir": "../rapier3d/", + "target_dir": "../rapier2d-minimal/", "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], - "js_package_name": "rapier3d-minimal", + "js_package_name": "rapier2d-minimal", "conditions_to_remove": ["DIM3", "SERDE_SERIALIZE", "DEBUG_RENDER"] } diff --git a/builds/prepare_builds/assets/example_dim3_minimal.json b/builds/prepare_builds/assets/example_dim3_minimal.json index 0fd8be41..98bcfff5 100644 --- a/builds/prepare_builds/assets/example_dim3_minimal.json +++ b/builds/prepare_builds/assets/example_dim3_minimal.json @@ -1,7 +1,7 @@ { "dim": "3", "feature_set": [], - "target_dir": "../rapier3d/", + "target_dir": "../rapier3d-minimal/", "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], diff --git a/builds/prepare_builds/build_all_projects.sh b/builds/prepare_builds/build_all_projects.sh index a8ed7840..0f799a02 100755 --- a/builds/prepare_builds/build_all_projects.sh +++ b/builds/prepare_builds/build_all_projects.sh @@ -12,7 +12,7 @@ do # FIXME: ideally we'd use `npm ci` # but we'd need to have generated the `package-lock` beforehand and committed them in the repository. # I'm not sure yet how to store those `package-lock`s yet though. - # They should proably be similar to all packages, but I'm not sure. + # They should probably be similar to all packages, but I'm not sure. npm i; npm run build; ) diff --git a/rapier-compat/build-rust.sh b/rapier-compat/build-rust.sh index c41470eb..dd21cade 100755 --- a/rapier-compat/build-rust.sh +++ b/rapier-compat/build-rust.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + help() { printf "Usage: %s: CONFIG_NAME\n" $0 @@ -21,7 +23,9 @@ rust_source_directory="../builds/${rust_source_directory_name}" if [ ! -d "$rust_source_directory" ]; then echo "Directory $rust_source_directory does not exist"; - echo "You may want to generate rust projects first."; + echo "You may want to generate rust projects first (see builds/prepare_builds folder)."; + echo "For example:"; + echo "> cd ../builds/prepare_builds && cargo run -- -c assets/$config_file_name.json && cd -" help exit 4; fi diff --git a/rapier-compat/gen_src.sh b/rapier-compat/gen_src.sh index a9878a7a..b0c3141c 100755 --- a/rapier-compat/gen_src.sh +++ b/rapier-compat/gen_src.sh @@ -34,7 +34,7 @@ cp -r ../src.ts/* $GENOUT rm -f "${GENOUT}/raw.ts" "${GENOUT}/init.ts" cp -r ./src${DIM}/* $GENOUT -for condition_to_remove in "${conditions_to_remove}" ; do +for condition_to_remove in ${conditions_to_remove} ; do # See https://serverfault.com/a/137848 echo "find ${GENOUT} -type f -print0 | LC_ALL=C xargs -0 sed -i.bak \"\\:#if ${condition_to_remove}:,\\:#endif:d\"" find ${GENOUT} -type f -print0 | LC_ALL=C xargs -0 sed -i.bak "\\:#if ${condition_to_remove}:,\\:#endif:d" From 81b97394bd877f153d097f1dd4637775597808f0 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Thu, 5 Jun 2025 12:13:18 +0200 Subject: [PATCH 09/12] prettyfier --- .github/workflows/minimal.yml | 74 +++++++++++++++++------------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/.github/workflows/minimal.yml b/.github/workflows/minimal.yml index 3a8a3154..e822cb69 100644 --- a/.github/workflows/minimal.yml +++ b/.github/workflows/minimal.yml @@ -1,44 +1,44 @@ name: minimal on: - push: - branches: [master] - pull_request: - branches: [master] - workflow_dispatch: + push: + branches: [master] + pull_request: + branches: [master] + workflow_dispatch: env: - CARGO_TERM_COLOR: always + CARGO_TERM_COLOR: always jobs: - build: - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - runs-on: ${{ matrix.os }} - env: - RUSTFLAGS: -D warnings - steps: - - uses: actions/checkout@v4 - - uses: actions/cache@v3 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - run: npm ci; - - name: Prepare minimal 2d build - working-directory: ./builds/prepare_builds/ - run: | - cargo run -- -c assets/example_dim2_minimal.json - - name: Build minimal 2d project - working-directory: ./builds/rapier2d-minimal - run: | - npm run build - - name: Build minimal 2d project compat - working-directory: ./rapier-compat - run: | - ./build_conf.sh example_dim2_minimal + build: + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + env: + RUSTFLAGS: -D warnings + steps: + - uses: actions/checkout@v4 + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - run: npm ci; + - name: Prepare minimal 2d build + working-directory: ./builds/prepare_builds/ + run: | + cargo run -- -c assets/example_dim2_minimal.json + - name: Build minimal 2d project + working-directory: ./builds/rapier2d-minimal + run: | + npm run build + - name: Build minimal 2d project compat + working-directory: ./rapier-compat + run: | + ./build_conf.sh example_dim2_minimal From 58ba8bcfca054e46b9e86e6a754d32e0b66c00cb Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Thu, 5 Jun 2025 14:05:01 +0200 Subject: [PATCH 10/12] add deps install for minimal compat --- .github/workflows/minimal.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/minimal.yml b/.github/workflows/minimal.yml index e822cb69..3e7ba353 100644 --- a/.github/workflows/minimal.yml +++ b/.github/workflows/minimal.yml @@ -29,11 +29,14 @@ jobs: ~/.cargo/git/db/ target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - run: npm ci; + - run: npm ci --development; - name: Prepare minimal 2d build working-directory: ./builds/prepare_builds/ run: | cargo run -- -c assets/example_dim2_minimal.json + - name: install rapier-compat dependencies + working-directory: ./rapier-compat + run: npm ci; - name: Build minimal 2d project working-directory: ./builds/rapier2d-minimal run: | From 7ef5372173a5d758b0e3e5895290ed199a09b0ce Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Fri, 6 Jun 2025 09:24:31 +0200 Subject: [PATCH 11/12] use npm for ci to run build_conf ; so wasmpack should be installed :crossed_fingers: --- .github/workflows/minimal.yml | 4 ++-- rapier-compat/build_conf.sh | 2 +- rapier-compat/{build-rust.sh => build_rust.sh} | 0 rapier-compat/package.json | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) rename rapier-compat/{build-rust.sh => build_rust.sh} (100%) diff --git a/.github/workflows/minimal.yml b/.github/workflows/minimal.yml index 3e7ba353..0799a6f1 100644 --- a/.github/workflows/minimal.yml +++ b/.github/workflows/minimal.yml @@ -29,7 +29,7 @@ jobs: ~/.cargo/git/db/ target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - run: npm ci --development; + - run: npm ci - name: Prepare minimal 2d build working-directory: ./builds/prepare_builds/ run: | @@ -44,4 +44,4 @@ jobs: - name: Build minimal 2d project compat working-directory: ./rapier-compat run: | - ./build_conf.sh example_dim2_minimal + npm run build-conf -- example_dim2_minimal diff --git a/rapier-compat/build_conf.sh b/rapier-compat/build_conf.sh index 7c31d058..b3cb6625 100755 --- a/rapier-compat/build_conf.sh +++ b/rapier-compat/build_conf.sh @@ -14,7 +14,7 @@ fi for config_file_name in "$@" do - ./build-rust.sh $config_file_name + ./build_rust.sh $config_file_name ./gen_src.sh $config_file_name npm run rollup -- --config rollup.config.js --bundleConfigAsCjs --environment BUILD_CONFIG_NAME:${config_file_name} diff --git a/rapier-compat/build-rust.sh b/rapier-compat/build_rust.sh similarity index 100% rename from rapier-compat/build-rust.sh rename to rapier-compat/build_rust.sh diff --git a/rapier-compat/package.json b/rapier-compat/package.json index bcdc73b8..4a70b8b1 100644 --- a/rapier-compat/package.json +++ b/rapier-compat/package.json @@ -7,6 +7,7 @@ "build-2d-all": "./build_conf.sh dim2 dim2_deterministic dim2_simd", "build-3d-all": "./build_conf.sh dim3 dim3_deterministic dim3_simd", "build-all": "./build_conf.sh dim2 dim3 dim2_deterministic dim3_deterministic dim2_simd dim3_simd", + "build-conf": "./build_conf.sh", "fix-raw-file": "sh ./fix_raw_file.sh", "build": "npm run clean && npm run build-all", "clean": "cargo clean && rimraf builds", From 1cc65864365422845e744404d57ee5258a915669 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Tue, 10 Jun 2025 10:10:21 +0200 Subject: [PATCH 12/12] rename some fields --- builds/prepare_builds/assets/dim2.json | 4 ++-- builds/prepare_builds/assets/dim2_deterministic.json | 8 ++++++-- builds/prepare_builds/assets/dim2_simd.json | 4 ++-- builds/prepare_builds/assets/dim3.json | 4 ++-- builds/prepare_builds/assets/dim3_deterministic.json | 8 ++++++-- builds/prepare_builds/assets/dim3_simd.json | 4 ++-- .../prepare_builds/assets/example_dim2_minimal.json | 8 ++++++-- .../prepare_builds/assets/example_dim3_minimal.json | 8 ++++++-- builds/prepare_builds/src/main.rs | 11 +++++++---- .../prepare_builds/templates/build_typescript.sh.tera | 2 +- rapier-compat/gen_src.sh | 4 ++-- 11 files changed, 42 insertions(+), 23 deletions(-) diff --git a/builds/prepare_builds/assets/dim2.json b/builds/prepare_builds/assets/dim2.json index 4a3ab8ca..52b11cac 100644 --- a/builds/prepare_builds/assets/dim2.json +++ b/builds/prepare_builds/assets/dim2.json @@ -1,10 +1,10 @@ { "dim": "2", - "feature_set": ["serde-serialize", "debug-render"], + "additional_features": ["serde-serialize", "debug-render"], "target_dir": "../rapier2d/", "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], "js_package_name": "rapier2d", - "conditions_to_remove": ["DIM3"] + "conditional_compilation_to_remove": ["DIM3"] } diff --git a/builds/prepare_builds/assets/dim2_deterministic.json b/builds/prepare_builds/assets/dim2_deterministic.json index 5b71b8aa..83d2bcef 100644 --- a/builds/prepare_builds/assets/dim2_deterministic.json +++ b/builds/prepare_builds/assets/dim2_deterministic.json @@ -1,10 +1,14 @@ { "dim": "2", - "feature_set": ["serde-serialize", "debug-render", "enhanced-determinism"], + "additional_features": [ + "serde-serialize", + "debug-render", + "enhanced-determinism" + ], "target_dir": "../rapier2d-deterministic", "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], "js_package_name": "rapier2d-deterministic", - "conditions_to_remove": ["DIM3"] + "conditional_compilation_to_remove": ["DIM3"] } diff --git a/builds/prepare_builds/assets/dim2_simd.json b/builds/prepare_builds/assets/dim2_simd.json index e1ff575d..34156ca1 100644 --- a/builds/prepare_builds/assets/dim2_simd.json +++ b/builds/prepare_builds/assets/dim2_simd.json @@ -1,10 +1,10 @@ { "dim": "2", - "feature_set": ["serde-serialize", "debug-render", "simd-stable"], + "additional_features": ["serde-serialize", "debug-render", "simd-stable"], "target_dir": "../rapier2d-simd", "template_dir": "./templates/", "additional_rust_flags": "-C target-feature=+simd128", "additional_wasm_opt_flags": ["--enable-simd"], "js_package_name": "rapier2d-simd", - "conditions_to_remove": ["DIM3"] + "conditional_compilation_to_remove": ["DIM3"] } diff --git a/builds/prepare_builds/assets/dim3.json b/builds/prepare_builds/assets/dim3.json index cdbcf637..9c68a10f 100644 --- a/builds/prepare_builds/assets/dim3.json +++ b/builds/prepare_builds/assets/dim3.json @@ -1,10 +1,10 @@ { "dim": "3", - "feature_set": ["serde-serialize", "debug-render"], + "additional_features": ["serde-serialize", "debug-render"], "target_dir": "../rapier3d/", "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], "js_package_name": "rapier3d", - "conditions_to_remove": ["DIM2"] + "conditional_compilation_to_remove": ["DIM2"] } diff --git a/builds/prepare_builds/assets/dim3_deterministic.json b/builds/prepare_builds/assets/dim3_deterministic.json index addba523..1d960491 100644 --- a/builds/prepare_builds/assets/dim3_deterministic.json +++ b/builds/prepare_builds/assets/dim3_deterministic.json @@ -1,10 +1,14 @@ { "dim": "3", - "feature_set": ["serde-serialize", "debug-render", "enhanced-determinism"], + "additional_features": [ + "serde-serialize", + "debug-render", + "enhanced-determinism" + ], "target_dir": "../rapier3d-deterministic", "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], "js_package_name": "rapier3d-deterministic", - "conditions_to_remove": ["DIM2"] + "conditional_compilation_to_remove": ["DIM2"] } diff --git a/builds/prepare_builds/assets/dim3_simd.json b/builds/prepare_builds/assets/dim3_simd.json index 038a200c..b5bb89db 100644 --- a/builds/prepare_builds/assets/dim3_simd.json +++ b/builds/prepare_builds/assets/dim3_simd.json @@ -1,10 +1,10 @@ { "dim": "3", - "feature_set": ["serde-serialize", "debug-render", "simd-stable"], + "additional_features": ["serde-serialize", "debug-render", "simd-stable"], "target_dir": "../rapier3d-simd", "template_dir": "./templates/", "additional_rust_flags": "-C target-feature=+simd128", "additional_wasm_opt_flags": ["--enable-simd"], "js_package_name": "rapier3d-simd", - "conditions_to_remove": ["DIM2"] + "conditional_compilation_to_remove": ["DIM2"] } diff --git a/builds/prepare_builds/assets/example_dim2_minimal.json b/builds/prepare_builds/assets/example_dim2_minimal.json index f6dd096d..1ae8dd55 100644 --- a/builds/prepare_builds/assets/example_dim2_minimal.json +++ b/builds/prepare_builds/assets/example_dim2_minimal.json @@ -1,10 +1,14 @@ { "dim": "2", - "feature_set": [], + "additional_features": [], "target_dir": "../rapier2d-minimal/", "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], "js_package_name": "rapier2d-minimal", - "conditions_to_remove": ["DIM3", "SERDE_SERIALIZE", "DEBUG_RENDER"] + "conditional_compilation_to_remove": [ + "DIM3", + "SERDE_SERIALIZE", + "DEBUG_RENDER" + ] } diff --git a/builds/prepare_builds/assets/example_dim3_minimal.json b/builds/prepare_builds/assets/example_dim3_minimal.json index 98bcfff5..14e052d7 100644 --- a/builds/prepare_builds/assets/example_dim3_minimal.json +++ b/builds/prepare_builds/assets/example_dim3_minimal.json @@ -1,10 +1,14 @@ { "dim": "3", - "feature_set": [], + "additional_features": [], "target_dir": "../rapier3d-minimal/", "template_dir": "./templates/", "additional_rust_flags": "", "additional_wasm_opt_flags": [], "js_package_name": "rapier3d-minimal", - "conditions_to_remove": ["DIM2", "SERDE_SERIALIZE", "DEBUG_RENDER"] + "conditional_compilation_to_remove": [ + "DIM2", + "SERDE_SERIALIZE", + "DEBUG_RENDER" + ] } diff --git a/builds/prepare_builds/src/main.rs b/builds/prepare_builds/src/main.rs index e37644fe..58a7f478 100644 --- a/builds/prepare_builds/src/main.rs +++ b/builds/prepare_builds/src/main.rs @@ -24,14 +24,14 @@ pub struct BuildValues { /// Only the number of dimensions (1 or 2), as sometimes it will be prefixed by "dim" and sometimes post-fixed by "d". pub dim: String, /// Rust name of the additional features to enable in the project, they should correspond to features from Cargo.toml(.tera). - pub feature_set: Vec, + pub additional_features: Vec, pub target_dir: PathBuf, pub template_dir: PathBuf, pub additional_rust_flags: String, pub additional_wasm_opt_flags: Vec, pub js_package_name: String, /// To remove text blocks present in non-rust files bounded by `#if CONDITION ... #endif` - pub conditions_to_remove: Vec, + pub conditional_compilation_to_remove: Vec, } impl BuildValues { @@ -100,14 +100,17 @@ fn process_templates(build_values: &BuildValues) -> std::io::Result<()> { let mut context = Context::new(); context.insert("dimension", &build_values.dim); - context.insert("additional_features", &build_values.feature_set); + context.insert("additional_features", &build_values.additional_features); context.insert("additional_rust_flags", &build_values.additional_rust_flags); context.insert( "additional_wasm_opt_flags", &build_values.additional_wasm_opt_flags, ); context.insert("js_package_name", &build_values.js_package_name); - context.insert("conditions_to_remove", &build_values.conditions_to_remove); + context.insert( + "conditional_compilation_to_remove", + &build_values.conditional_compilation_to_remove, + ); let tera = match Tera::new(target_dir.join("**/*.tera").to_str().unwrap()) { Ok(t) => t, diff --git a/builds/prepare_builds/templates/build_typescript.sh.tera b/builds/prepare_builds/templates/build_typescript.sh.tera index 9eea9e2c..b710339d 100755 --- a/builds/prepare_builds/templates/build_typescript.sh.tera +++ b/builds/prepare_builds/templates/build_typescript.sh.tera @@ -5,7 +5,7 @@ cp -r ../../src.ts/* pkg/src/. rm -f ./pkg/raw.ts echo 'export * from "./rapier_wasm{{ dimension }}d"' > pkg/src/raw.ts # See https://serverfault.com/a/137848 -{% for condition_to_remove in conditions_to_remove %} +{% for condition_to_remove in conditional_compilation_to_remove %} find pkg/ -type f -print0 | LC_ALL=C xargs -0 sed -i.bak '\:#if {{condition_to_remove}}:,\:#endif:d' {% endfor %} npx tsc diff --git a/rapier-compat/gen_src.sh b/rapier-compat/gen_src.sh index b0c3141c..330dce05 100755 --- a/rapier-compat/gen_src.sh +++ b/rapier-compat/gen_src.sh @@ -18,7 +18,7 @@ config_file_path="../builds/prepare_builds/assets/$config_file_name.json" js_package_name=`node -pe 'JSON.parse(process.argv[1]).js_package_name' "$(cat ${config_file_path})"` dimension=`node -pe 'JSON.parse(process.argv[1]).dim' "$(cat ${config_file_path})"` -conditions_to_remove=`node -pe 'JSON.parse(process.argv[1]).conditions_to_remove.join(" ")' "$(cat ${config_file_path})"` +conditional_compilation_to_remove=`node -pe 'JSON.parse(process.argv[1]).conditional_compilation_to_remove.join(" ")' "$(cat ${config_file_path})"` DIM="${dimension}d" GENOUT="./builds/${js_package_name}/gen${DIM}" @@ -34,7 +34,7 @@ cp -r ../src.ts/* $GENOUT rm -f "${GENOUT}/raw.ts" "${GENOUT}/init.ts" cp -r ./src${DIM}/* $GENOUT -for condition_to_remove in ${conditions_to_remove} ; do +for condition_to_remove in ${conditional_compilation_to_remove} ; do # See https://serverfault.com/a/137848 echo "find ${GENOUT} -type f -print0 | LC_ALL=C xargs -0 sed -i.bak \"\\:#if ${condition_to_remove}:,\\:#endif:d\"" find ${GENOUT} -type f -print0 | LC_ALL=C xargs -0 sed -i.bak "\\:#if ${condition_to_remove}:,\\:#endif:d"