Skip to content

Commit

Permalink
Merge pull request #48 from paulcadman/option-disable-resvg
Browse files Browse the repository at this point in the history
Add option to disable build / link / use of resvg
  • Loading branch information
paulcadman authored Nov 26, 2024
2 parents 3e5e1a5 + 13df009 commit a2c252a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
12 changes: 12 additions & 0 deletions c/raylib_bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ lean_obj_res image_height(b_lean_obj_arg image) {
return lean_uint32_to_nat(image_of_arg(image)->height);
}


#ifdef RAYLEAN_NO_RESVG

Image loadImageFromData(const char *ext, const char *data, size_t size) {
return LoadImageFromMemory(ext, (unsigned char *)data, size);
}

#else

Image loadImageFromData(const char *ext, const char *data, size_t size) {
if (strcmp(".svg", ext) == 0 || strcmp(".SVG", ext) == 0) {
Image image = {0};
Expand Down Expand Up @@ -187,6 +196,9 @@ Image loadImageFromData(const char *ext, const char *data, size_t size) {
}
}


#endif

// Load an image from a resource
// Resources are loaded from the resources/ directory in the project
lean_obj_res loadImage(b_lean_obj_arg resource_name_arg) {
Expand Down
34 changes: 24 additions & 10 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# set to non-empty string to disable use of resvg for SVG support.
#
# e.g:
# just disableResvg=yes build
disableResvg := ''

# set to non-empty string to disable use of the resource bundle.
#
# e.g:
# just disableBundle=yes build
disableBundle := ''

lake_bundle_config_opt := if disableBundle == "" { "-K bundle=on" } else { "" }

lake_resvg_config_opt := if disableResvg == "" { "" } else { "-K resvg=disable" }

# Flags used to configure the lake build
lake_config_opts := if disableBundle == "" { "-K bundle=on" } else { "" }
lake_config_opts := lake_bundle_config_opt + " " + lake_resvg_config_opt

# Raylib CUSTOM_FLAGS tailed for the current os
#
Expand Down Expand Up @@ -50,20 +60,24 @@ default:
check_cargo:
#!/usr/bin/env bash
set -euo pipefail
if ! command -v cargo &> /dev/null
then
echo "cargo was not found. Please install rust: https://rustup.rs"
exit 1
if [ -z "{{disableResvg}}" ]; then
if ! command -v cargo &> /dev/null
then
echo "cargo was not found. Please install rust: https://rustup.rs"
exit 1
fi
fi
# build only the resvg static library
build_resvg: check_cargo
#!/usr/bin/env bash
set -euo pipefail
cd {{resvg_c_api_path}}
cargo build --release
mkdir -p {{static_lib_path}}
cp {{resvg_c_api_path}}/../../target/release/libresvg.a {{static_lib_path}}
if [ -z "{{disableResvg}}" ]; then
set -euo pipefail
cd {{resvg_c_api_path}}
cargo build --release
mkdir -p {{static_lib_path}}
cp {{resvg_c_api_path}}/../../target/release/libresvg.a {{static_lib_path}}
fi
# build only the raylib static library
build_raylib:
Expand Down
8 changes: 7 additions & 1 deletion lakefile.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ open System Lake DSL

def optionUseBundle : Bool := get_config? bundle == some "on"

def optionDisableResvg : Bool := get_config? resvg == some "disable"

require batteries from git "https://github.com/leanprover-community/batteries.git" @ "01f4969b6e861db6a99261ea5eadd5a9bb63011b" -- Lean v4.14.0-rc1

package «raylean» where
Expand All @@ -22,7 +24,9 @@ lean_lib «Lens»
lean_exe «raylean» where
root := `Main
moreLinkArgs := Id.run do
let mut args := #[ "lib/libraylib.a" , "lib/libresvg.a"]
let mut args := #[ "lib/libraylib.a"]
if not optionDisableResvg then
args := args ++ #["lib/libresvg.a"]
if (← System.Platform.isOSX) then
args := args ++
#[ "-isysroot", "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
Expand Down Expand Up @@ -53,6 +57,8 @@ target raylib_bindings.o pkg : FilePath := do
let resvgInclude := pkg.dir / "resvg-0.43.0" / "crates" / "c-api"
let weakArgs := #["-I", s!"{raylibInclude}", "-I", s!"{includes}", "-I", s!"{resvgInclude}"]
let mut traceArgs := #["-fPIC"]
if optionDisableResvg then
traceArgs := traceArgs ++ #["-DRAYLEAN_NO_RESVG"]
if not (optionUseBundle) then
traceArgs := traceArgs ++ #["-DRAYLEAN_NO_BUNDLE"]
buildLeanO oFile srcJob weakArgs traceArgs
Expand Down

0 comments on commit a2c252a

Please sign in to comment.