Building on Windows #123
-
|
Does anyone have any insights on how to get a build working on Windows? I know the parent library can be built on Windows but this version only has Linux build.sh scripts. I went through the build manually and got Also tried on my Mac but it threw a bunch of cmake/Unix errors... I suppose I could spin up a distro/container but that's a lot of hoops when a windows build shouldn't be too hard. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
|
I used WSL under Windows to build it, since I have Emscripten and build tools installed there. Haven't tried using normal power shell / bash, as I would need to set up the environment. Curious what would it take to set up a docker container, similar to Ammo - pretty convenient way to build it, as no need to install emsc, etc. |
Beta Was this translation helpful? Give feedback.
-
|
I use WSL as well, it's super simple to download e.g. Ubuntu from the windows store and run it there. When I started this project, I tried building under windows but emscripten wasn't working for some reason, so I just went for Linux. |
Beta Was this translation helpful? Give feedback.
-
|
(updated comment , see original for full version) Hello, it took me a couple of days to get this working and didn't find any example, so thought I'd share in case anyone else wants to build the lib on a Windows machine with double precision enabled. Key Updates Made:
Updated build.ps1# Clean Build directory
Remove-Item -Recurse -Force ./Build -ErrorAction SilentlyContinue
$ErrorActionPreference = "Stop"
$buildType = if ($args.Count -gt 0) { $args[0] } else { "Distribution" }
$numProcs = (Get-CimInstance -ClassName Win32_Processor).NumberOfLogicalProcessors
# Remove dist if exists
Remove-Item -Recurse -Force ./dist -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Path ./dist | Out-Null
if ($buildType -ne "Debug") {
# Build Debug ST with double precision
emcmake cmake -B Build/Debug/ST -DCMAKE_BUILD_TYPE=Debug -DBUILD_WASM_COMPAT_ONLY=ON -DDOUBLE_PRECISION=ON
cmake --build Build/Debug/ST -j $numProcs
# Build Debug MT with double precision
emcmake cmake -B Build/Debug/MT -DENABLE_MULTI_THREADING=ON -DENABLE_SIMD=ON -DCMAKE_BUILD_TYPE=Debug -DBUILD_WASM_COMPAT_ONLY=ON -DDOUBLE_PRECISION=ON
cmake --build Build/Debug/MT -j $numProcs
# Rename for debug
if (Test-Path ./dist/jolt-physics.wasm-compat.js) { Move-Item ./dist/jolt-physics.wasm-compat.js ./dist/jolt-physics.debug.wasm-compat.js }
if (Test-Path ./dist/jolt-physics.multithread.wasm-compat.js) { Move-Item ./dist/jolt-physics.multithread.wasm-compat.js ./dist/jolt-physics.debug.multithread.wasm-compat.js }
}
# Build the specified type ST with double precision
$stPath = "Build/$buildType/ST"
$mtPath = "Build/$buildType/MT"
emcmake cmake -B $stPath "-DCMAKE_BUILD_TYPE=$buildType" -DDOUBLE_PRECISION=ON
cmake --build $stPath -j $numProcs
# Build the specified type MT with double precision
emcmake cmake -B $mtPath -DENABLE_MULTI_THREADING=ON -DENABLE_SIMD=ON "-DCMAKE_BUILD_TYPE=$buildType" -DDOUBLE_PRECISION=ON
cmake --build $mtPath -j $numProcs
if ($buildType -eq "Debug") {
$debugWasmCompat = "./dist/jolt-physics.debug.wasm-compat.js"
$debugMtWasmCompat = "./dist/jolt-physics.debug.multithread.wasm-compat.js"
if (Test-Path ./dist/jolt-physics.wasm-compat.js) { Copy-Item ./dist/jolt-physics.wasm-compat.js $debugWasmCompat }
if (Test-Path ./dist/jolt-physics.multithread.wasm-compat.js) { Copy-Item ./dist/jolt-physics.multithread.wasm-compat.js $debugMtWasmCompat }
}
# Update worker URL for debug multithread
if (Test-Path ./dist/jolt-physics.debug.multithread.wasm-compat.js) {
$debugMtContent = Get-Content ./dist/jolt-physics.debug.multithread.wasm-compat.js -Raw
$debugMtContent = $debugMtContent -replace 'jolt-physics.multithread.wasm-compat.js', 'jolt-physics.debug.multithread.wasm-compat.js'
$debugMtContent | Set-Content ./dist/jolt-physics.debug.multithread.wasm-compat.js -NoNewline -Encoding utf8
}
# Create d.ts file
$dtsContent = @"
import Jolt from "./types";
export default Jolt;
export * from "./types";
"@
$dtsContent | Out-File ./dist/jolt-physics.d.ts -Encoding utf8
# Copy d.ts to various names (CRITICAL for TypeScript support)
$tsFiles = @(
'jolt-physics.wasm.d.ts',
'jolt-physics.wasm-compat.d.ts',
'jolt-physics.debug.wasm-compat.d.ts',
'jolt-physics.multithread.d.ts',
'jolt-physics.multithread.wasm.d.ts',
'jolt-physics.multithread.wasm-compat.d.ts',
'jolt-physics.debug.multithread.wasm-compat.d.ts'
)
foreach ($file in $tsFiles) {
Copy-Item ./dist/jolt-physics.d.ts ./dist/${file}
}
# Copy wasm-compat js to Examples/js
Get-ChildItem ./dist -Filter 'jolt-physics*.wasm-compat.js' -ErrorAction SilentlyContinue | ForEach-Object { Copy-Item $_.FullName ./Examples/js/ }Key Changes Made:
Verification:After building, you can verify double precision is working: import Jolt from './dist/jolt-physics.wasm-compat.js';
async function verifyDoublePrecision() {
const JoltModule = await Jolt();
// Test at 2.8 million km (your reported distance)
const testDistance = 2800000000.0;
const rvec = new JoltModule.RVec3(testDistance, 0.0, 0.0);
const retrieved = rvec.GetX();
const diff = Math.abs(retrieved - testDistance);
const precision = diff / testDistance;
console.log(`Precision: ${precision.toExponential()}`);
// Should show 0e+0 (perfect precision) with double precision enabled
}Installation:After building, create and install the package: # Create package
npm pack
# Install in another project
npm install D:\path\to\jolt-physics-0.38.0.tgz |
Beta Was this translation helpful? Give feedback.
I use WSL as well, it's super simple to download e.g. Ubuntu from the windows store and run it there. When I started this project, I tried building under windows but emscripten wasn't working for some reason, so I just went for Linux.