Skip to content

Commit ff05a28

Browse files
authored
raylib hello (#570)
* raylib hello * work on linu * buildifier
1 parent 7dd496c commit ff05a28

15 files changed

+159
-64
lines changed

MODULE.bazel.lock

+27-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bazel/3p/BUILD.bazel

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
alias(
2+
name = "raylib",
3+
actual = select({
4+
":is_linux": "@raylib_linux//:raylib_linux",
5+
":is_mac": "@raylib_macos//:raylib_macos",
6+
}),
7+
visibility = ["//visibility:public"],
8+
)
9+
10+
config_setting(
11+
name = "is_mac",
12+
constraint_values = [
13+
"@platforms//cpu:aarch64",
14+
"@platforms//os:macos",
15+
],
16+
)
17+
18+
config_setting(
19+
name = "is_linux",
20+
constraint_values = [
21+
"@platforms//cpu:x86_64",
22+
"@platforms//os:linux",
23+
],
24+
)

bazel/3p/mongoose.BUILD

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library")
2+
3+
cc_library(
4+
name = "mongoose",
5+
srcs = ["mongoose.c"],
6+
hdrs = ["mongoose.h"],
7+
visibility = ["//visibility:public"],
8+
)

bazel/3p/raylib.BUILD

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_import")
2+
3+
cc_import(
4+
name = "raylib_linux",
5+
hdrs = [
6+
"include/raylib.h",
7+
"include/raymath.h",
8+
"include/rlgl.h",
9+
],
10+
shared_library = "lib/libraylib.so.550",
11+
target_compatible_with = [
12+
"@platforms//os:linux",
13+
"@platforms//cpu:x86_64",
14+
],
15+
visibility = ["//visibility:public"],
16+
)
17+
18+
cc_import(
19+
name = "raylib_macos",
20+
hdrs = [
21+
"include/raylib.h",
22+
"include/raymath.h",
23+
"include/rlgl.h",
24+
],
25+
shared_library = "lib/libraylib.550.dylib",
26+
target_compatible_with = [
27+
"@platforms//os:macos",
28+
"@platforms//cpu:aarch64",
29+
],
30+
visibility = ["//visibility:public"],
31+
)

bazel/cc.MODULE.bazel

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ bazel_dep(name = "rules_cc", version = "0.1.1")
22
bazel_dep(name = "grpc", version = "1.70.1", repo_name = "com_github_grpc_grpc")
33
bazel_dep(name = "abseil-cpp", version = "20250127.0", repo_name = "com_google_absl")
44
bazel_dep(name = "googletest", version = "1.16.0")
5-
# bazel_dep(name = "rules_apple", version = "3.13.0", repo_name = "build_bazel_rules_apple")
6-
# bazel_dep(name = "apple_support", version = "1.17.1")
75

86
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
97
git_override(
@@ -12,5 +10,5 @@ git_override(
1210
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
1311
)
1412

15-
non_module_deps = use_extension("//bazel:extensions.bzl", "non_module_deps")
16-
use_repo(non_module_deps, "mongoose_cc")
13+
non_module_deps = use_extension("//bazel/extensions:extensions.bzl", "non_module_deps")
14+
use_repo(non_module_deps, "mongoose_cc", "raylib_linux", "raylib_macos")

bazel/extensions.bzl

-23
This file was deleted.
File renamed without changes.

bazel/extensions/extensions.bzl

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"bzlmod extensions"
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
def _http_impl(ctx): # buildifier: disable=unused-variable
6+
http_archive(
7+
name = "mongoose_cc",
8+
strip_prefix = "mongoose-7.16",
9+
sha256 = "f2c42135f7bc34b3d10b6401e9326a20ba5dd42d4721b6a526826ba31c1679fd",
10+
urls = ["https://github.com/cesanta/mongoose/archive/refs/tags/7.16.tar.gz"],
11+
build_file = "@//bazel/3p:mongoose.BUILD",
12+
)
13+
14+
http_archive(
15+
name = "raylib_macos",
16+
urls = ["https://github.com/raysan5/raylib/releases/download/5.5/raylib-5.5_macos.tar.gz"],
17+
sha256 = "930c67b676963c6cffbd965814664523081ecbf3d30fc9df4211d0064aa6ba39",
18+
strip_prefix = "raylib-5.5_macos",
19+
build_file = "@//bazel/3p:raylib.BUILD",
20+
)
21+
22+
http_archive(
23+
name = "raylib_linux",
24+
urls = ["https://github.com/raysan5/raylib/releases/download/5.5/raylib-5.5_linux_amd64.tar.gz"],
25+
sha256 = "3d95ef03d5b38dfa55c0a16ca122d382134b078f0e5b270b52fe7eae0549c000",
26+
strip_prefix = "raylib-5.5_linux_amd64",
27+
build_file = "@//bazel/3p:raylib.BUILD",
28+
)
29+
30+
non_module_deps = module_extension(implementation = _http_impl)

bazel/patches/grpc_extra_deps.patch

-13
This file was deleted.

bazel/patches/mongoose.patch

-13
This file was deleted.

bazel/rust.MODULE.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ register_toolchains("@rust_toolchains//:all")
1111

1212
register_toolchains("@rules_rust//proto/protobuf:default-proto-toolchain")
1313

14-
register_toolchains("//tools/toolchains:prost_toolchain")
14+
register_toolchains("//bazel/toolchains:prost_toolchain")
1515

1616
crate = use_extension(
1717
"@rules_rust//crate_universe:extension.bzl",
File renamed without changes.

cpp/example_raylib/BUILD.bazel

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_binary")
2+
3+
cc_binary(
4+
name = "example_raylib",
5+
srcs = ["main.cc"],
6+
deps = [
7+
"//bazel/3p:raylib",
8+
],
9+
)

cpp/example_raylib/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Raylib Hello World
2+
3+
Todo:
4+
- [x] works on mac
5+
- [x] works on linux
6+
- [ ] figure out how to write tests

cpp/example_raylib/main.cc

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "include/raylib.h"
2+
3+
int main() {
4+
int screenWidth = 400;
5+
int screenHeight = 200;
6+
7+
InitWindow(screenWidth, screenHeight, "Hello, World!");
8+
9+
SetTargetFPS(60);
10+
SetExitKey(-1); // don't exit on ESC
11+
12+
while (!WindowShouldClose()) {
13+
BeginDrawing();
14+
ClearBackground(RAYWHITE);
15+
DrawText("hello raylib", screenWidth / 2 - 50, screenHeight / 2, 20, BLACK);
16+
EndDrawing();
17+
}
18+
19+
CloseWindow();
20+
return 0;
21+
}

0 commit comments

Comments
 (0)