Raylib.lean
Lean4 bindings to raylib 5.6-dev, including Raymath and Raygui 4.0-dev.
Examples
Running (on Linux only):
- Clone this repository
cdinto cloned repository rootlake -R -Kfork -Kraygui run raylib/buildSubmodulelake exe raylib-examples-minimal
Examples assume working directory to be the library repository root. Some require certain lake configuration options to be set (command above configures them).
See also: raylib's examples directory.
Installation
Add this to lakefile.lean:
require raylib from git
"https://github.com/KislyjKisel/Raylib.lean" @ "main"
To the lean_exe target add:
moreLinkArgs := #["-Llake-packages/raylib/raylib/build/raylib", "-lraylib"]
Then run lake update and lake run raylib/buildSubmodule.
Installation problems
-
First build may take some time (around 10-20 minutes) to download raylib.
-
On the first build git may return error 128. Usually restarting the build or re-cloning the raylib's repo helps.
-
By default Lean's built-in C compiler is used to build ffi. On Windows it fails due to missing stdlib headers. You can use a different C compiler by passing the
ccoption with the compilers path (options are described above). To build raylibcmakeandgitfromPATHare used. If you don't have them in PATH you can provide their paths with optionsgitandcmake. If you want to clone and/or build raylib manually you can provide emptygitandcmakeoptions and then run required commands (which can be found in the lakefile inbuildRaylibSubmodule). You can also userayliboption set tocustomand provide separately built raylib via thecflagsoptions (andlflagsfor examples). See #3 and #5, actions. This may help too (fixedld.lld: PlaySound was replacedfor me). -
On macOS additional link arguments are required to build executables using raylib, see #6. Lean's builtin C compiler, which is used for linking by default, can have trouble finding required frameworks. You can use another C compiler for linking by setting
LEAN_CCenvironment variable. Then you need to add-L.../toolchains/..lean4../lib, see examples link arguments in the lakefile.By default
cmakeandgitare assumed to be inPATH. Their use can be configured via lake options.
Options
Options can be specified by appending with $opts (where $opts is a NameMap) to the require statement
raylib:"submodule"(default) to compile from source using git submodules."system"to find usingpkg-config(uses hardcoded paths for examples)."custom"to not pass library or header directories to the compiler.raygui: allows usingRaygui, downloads it as a submodule.cc: c compiler invoked used to build native code. By default uses (ordered by priority)LEAN_CC, the compiler provided by Lean toolchain orcc.cflags: additional flags passed to the native code compiler.lflags: additional flags used to link examples.extraCmakeArgs: additional arguments passed to cmake when building submodule.cmdout: if present, print output of commands used when building submodule.fork: use raylib's fork that provides features used by implementations of some functions (notably audio callbacks) and some more.alloc: allocator for external (opaque ffi) objects."lean"(default) means using the allocator Lean uses."native"to usemallocandfreeinstead.git,cmake: git and cmake used to build raylib submodule, or""(empty string) to skip their respective steps.precompileRaymath: if set enablesprecompileModulesfor Raymath.- Web build can additionally be configured using:
emcmake,emcc: build tools, defaults toemcmakeandemcc.extraEmccArgs: extraemccarguments.extraEmccSources: takes a spaces separated list of paths with wildcards (*and**), files matching these paths will be added toemccarguments.webShell: passed toemccas a--shell-file, defaults to raylib'sminshell.html.wasmToolchain: path to downloaded and unpackedlean-$LEAN_VERSION-linux_wasm32.
disableMacosLinkArgs: do not add macos specific link arguments to examples.enableWindowsMingw: add lean's "lib" directory,System32,-lgdi32,-lopengl32,-lmsvcrtto examples link arguments; add-G Unix Makefilesand-DSUPPORT_WINMM_HIGHRES_TIMER=OFFto cmake build arguments.
There are also options to customize raylib build.
Scripts
buildSubmodule: initializes submodule and builds it. Runs as part of the bindings build process.cleanCmakeCache: removesbuilddirectory from the submodule.options: prints configured lake options (doesn't include cmake build options).buildWeb {exeName}: builds an executable target without linking, then compiles produced IR C sources and files matching user-provided patterns usingemcc(see options).



