{"id":21367536,"url":"https://github.com/thejustinwalsh/sh-raylib","last_synced_at":"2025-07-13T05:31:47.799Z","repository":{"id":210975497,"uuid":"721839150","full_name":"thejustinwalsh/sh-raylib","owner":"thejustinwalsh","description":"raylib bindings for static hermes","archived":false,"fork":false,"pushed_at":"2023-12-06T09:26:42.000Z","size":5864,"stargazers_count":28,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-01T19:49:48.010Z","etag":null,"topics":["cmake","hermes","raylib","shermes"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thejustinwalsh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-11-21T21:59:11.000Z","updated_at":"2024-04-28T19:19:36.000Z","dependencies_parsed_at":"2023-12-05T20:51:14.709Z","dependency_job_id":null,"html_url":"https://github.com/thejustinwalsh/sh-raylib","commit_stats":null,"previous_names":["thejustinwalsh/sh-raylib"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thejustinwalsh%2Fsh-raylib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thejustinwalsh%2Fsh-raylib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thejustinwalsh%2Fsh-raylib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thejustinwalsh%2Fsh-raylib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thejustinwalsh","download_url":"https://codeload.github.com/thejustinwalsh/sh-raylib/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225856920,"owners_count":17535144,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmake","hermes","raylib","shermes"],"created_at":"2024-11-22T07:19:34.368Z","updated_at":"2024-11-22T07:19:34.954Z","avatar_url":"https://github.com/thejustinwalsh.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# raylib bindings for Static Hermes\n\u003e This is highly experimental and likely not suitable for use.\n\n## Prerequisites\n```sh\nbrew install cmake git ninja python3 castxml\n```\n\n## Building\n```sh\ncmake -B ./build -G Ninja -DCMAKE_BUILD_TYPE=Release\ncmake --build ./build\n```\n\n## Running\n```sh\n./build/bin/hello-world\n./build/bin/bunny-mark\n```\n\n## Static Hermes vs Pure C\n```sh\ncd ./build/bin\n./bunny-mark\n./bunny-mark-c\n```\n`bunny-mark-c` is the original bunny-mark example from raylib.\n`bunny-mark` is the same example, ported to typescript and slightly modified to compiled with shermes.\n\n# Notes\n\n## Running ffigen\n```sh\nbrew install python3 castxml\n```\n\n`hermes/tools/ffigen/ffigen.py` uses [castxml](https://github.com/CastXML/CastXML) to generate an AST of the c/cpp code and emit function definitions for the headers that you tell it to parse.\n\nIf a function returns a struct or union you will also need to run ffigen cwrap in order to generate wrapper functions that turn the return param into an out param as the first argument.\n\nYou can limit the scope of the headers that ffigen will include, so that you don't pick up system headers, or other undesired headers from the include chain.\n\n## Generating raylib externs\n```sh\nffigen js ./raylib-ffi.h builtin,raylib.h,raymath.h \u003e js_externs.js\nffigen cwrap ./raylib-ffi.h builtin,raylib.h,raymath.h \u003e js_externs_cwrap.c\n```\n\nIn order to get the raylib headers to parse properly you must ensure that the defines were present that raylib expects in order to use c99 stdbool, instead of some custom unsupported bool type. This is done in `raylib-ffi.h` by defining `__STDC_VERSION__` to `199901L` and `__STDC__` to `1`. There may be a better way to do this moving forward, but I did not see anyway to past args through ffigen to castxml.\n\nThe generated cwrap externs require you to include the headers that you are generating externs for, otherwise you will get errors about missing types. This is because the cwrap externs are just wrappers around the original functions, and they need to know about the types that they are wrapping. Some creative use of `cmake -E cat` to concatenate the headers into a single file is implemented in `src/shared/CMakeLists.txt` to make this work.\n\n## Working with cwrap externs\nYou must allocate memory for the return value of the function, and pass it as the first argument to the cwrap function. The cwrap function will then copy the return value into the memory that you allocated.\n\n```ts\nconst ptr = malloc(_sizeof_Font);\n_LoadFont(ptr, \"path/to/font.png\");\n```\n\n## Memory management\nEvery malloc should be paired with a free. If you are allocating memory for a return value, you should free it after you are done with it.\nOnce finalizers are implemented we can design some better memory lifetimes and access patterns wrapped up in a higher level API.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthejustinwalsh%2Fsh-raylib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthejustinwalsh%2Fsh-raylib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthejustinwalsh%2Fsh-raylib/lists"}