BUILD.mdpreviewBUILD.mdsource82 lines · 3.6 KB · raw

Dependencies

Rust

This project requires the latest stable version of the Rust toolchain to build.

SDL3

This project uses SDL3 for windowing, audio playback, and reading keyboard/gamepad/mouse inputs.

By default, SDL3 is fetched and built from source while building this project, and it is dynamically linked at runtime. This behavior is customizable using Cargo features:

FeatureDescriptionDefault
sdl3-build-from-sourceFetch and build SDL3 from sourceYes
sdl3-static-linkStatically link SDL3No

Building SDL3 from source requires a C build toolchain. See also:

Example command to disable building SDL3 from source:

cargo build --no-default-features

Example command to build while statically linking SDL3:

cargo build --features sdl3-static-link

If SDL3 is not statically linked, it must be available in the dynamic library path at runtime. cargo run handles this automatically when the sdl3-build-from-source feature is enabled.

If sdl3-build-from-source is disabled, SDL3 headers and libraries must be available at build time, e.g. by installing the libsdl3-dev package on Linux. If they are not in the system library path then you may need to use RUSTFLAGS to pass -I and -L arguments to the linker.

DirectX Shader Compiler (Windows DX12 backend only)

The DirectX 12 wgpu backend is currently configured in such a way that it requires DLLs for Microsoft's DirectX shader compiler. The latest release is available here: https://github.com/microsoft/DirectXShaderCompiler/releases

dxcompiler.dll must be present in the current working directory for the DirectX 12 backend to work.

Build & Run

Build and run:

cargo run --release

For local development, the dev-fast profile has a lower optimization level and should have faster incremental compile times (at the cost of worse runtime performance):

cargo run --profile dev-fast

For one-time builds, the release-lto profile enables fat LTOs and a few other build settings that improve runtime performance and decrease binary size at the cost of much longer compile times:

cargo build --profile release-lto

...After which the binaries will be in target/release-lto/.

If you are building for usage solely on your own machine, you can additionally set the compiler flag -C target-cpu=native to tell the compiler that it can use any CPU instruction that your computer's CPU supports, which may slightly improve performance:

RUSTFLAGS="-C target-cpu=native" cargo build --profile release-lto

-C target-cpu=native is not recommended for shared or distributed builds because the binaries may contain instructions that are only supported on recent CPUs, e.g. AVX-512 instructions. For shared/distributed builds it is better to use a specific CPU target such as -C target-cpu=x86-64-v3 (allows the compiler to use AVX2, FMA, LZCNT, etc).

On Linux, the following command will build AppImage packages (requires a nightly Rust toolchain and cargo-packager):

cargo packager --profile release-lto -f appimage