From 910f63bf0784a616b2a5695ef9f2c05d95e9696e Mon Sep 17 00:00:00 2001 From: laentropia Date: Tue, 26 May 2026 22:28:06 -0600 Subject: [PATCH] Initial commit, first project from 0 with xmake --- .gitignore | 60 +++++++++++++++++++++++++++++ include/lae_strings.h | 6 +++ src/lae_strings.c | 9 +++++ src/main.c | 18 +++++++++ test/test_string.c | 11 ++++++ xmake.lua | 88 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 192 insertions(+) create mode 100644 .gitignore create mode 100644 include/lae_strings.h create mode 100644 src/lae_strings.c create mode 100644 src/main.c create mode 100644 test/test_string.c create mode 100644 xmake.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0af733a --- /dev/null +++ b/.gitignore @@ -0,0 +1,60 @@ +# Directories +build/ +build-*/ +cmake-build-*/ +.cache/ +out/ +out/Debug/ +out/Release/ + +# xmake +xmake/ +.xmake/* +.xmake + +# Cmake files +CMakeCache.txt +cmake +CMakeFiles/ +cmake_install.cmake +CTestTestfile.cmake +Testing/ +compile_commands.json +../compile_commands.json +build/compile_commands.json + +# Make / Ninja +Makefile +*.ninja +*.ninja_deps +*.ninja_log +rules.ninja + +# Object files +*.o +*.obj +*.lo +*.la + +# Binaries +*.out +*.exe +*.dll +*.so +*.so.* +*.dylib +*.a + +# Debug / Sanitizer +*.dSYM/ +*.gcno +*.gcda +*.gcov + +# Editors +.vscode/ +.idea/ +*.swp +*.swo +*~ + diff --git a/include/lae_strings.h b/include/lae_strings.h new file mode 100644 index 0000000..ea61f21 --- /dev/null +++ b/include/lae_strings.h @@ -0,0 +1,6 @@ +#ifndef LAE_STRINGS_H +#define LAE_STRINGS_H + +typedef struct ByteStr ByteStr; + +#endif diff --git a/src/lae_strings.c b/src/lae_strings.c new file mode 100644 index 0000000..87bfc52 --- /dev/null +++ b/src/lae_strings.c @@ -0,0 +1,9 @@ +#include "lae_strings.h" +#include +#include + +struct ByteStr { + uint8_t* buf; + size_t len; + size_t cap; +}; diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..b9c4c40 --- /dev/null +++ b/src/main.c @@ -0,0 +1,18 @@ +#include "mylib.h" + +#include +#include + +int main(void) { + MyLib *lib = mylib_create(); + if (!lib) { + fprintf(stderr, "Error: could not create MyLib\n"); + return EXIT_FAILURE; + } + + int result = mylib_do_something(lib, 42); + printf("Result: %d\n", result); + + mylib_destroy(lib); + return EXIT_SUCCESS; +} diff --git a/test/test_string.c b/test/test_string.c new file mode 100644 index 0000000..6e550ee --- /dev/null +++ b/test/test_string.c @@ -0,0 +1,11 @@ +#include +#include +#include /* required by cmocka */ +#include +#include + +#include "lae_strings.h" + +int main(void) { + return EXIT_SUCCESS; +} diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..e1b4a6b --- /dev/null +++ b/xmake.lua @@ -0,0 +1,88 @@ +set_project("lae_strings") +set_version("1.0.0") + +set_languages("c11") + +add_rules("mode.debug", "mode.release") + +-- Export compile_commands.json +add_rules("plugin.compile_commands.autoupdate") + +-- ========================================================= +-- Options +-- ========================================================= + +option("tests") +set_default(false) +set_showmenu(true) +option_end() + +option("example") +set_default(false) +set_showmenu(true) +option_end() + +option("asan") +set_default(false) +set_showmenu(true) +option_end() + +-- ========================================================= +-- Packages +-- ========================================================= + +add_requires("cmocka", { optional = true }) +add_requires("lae_allocator") + +-- ========================================================= +-- Library +-- ========================================================= + +target("lae_strings") +set_kind("static") + +add_packages("lae_allocator") + +add_files("src/lae_strings.c") + +add_headerfiles("include/*.h") + +add_includedirs("include", { public = true }) + +if is_mode("debug") then + add_cflags("-Wall", "-Wextra", "-Wpedantic") +end + +-- ========================================================= +-- Example executable +-- ========================================================= + +if has_config("example") then + target("example") + set_kind("binary") + + add_files("src/main.c") + + add_deps("lae_strings") +end + +-- ========================================================= +-- Tests +-- ========================================================= + +if has_config("tests") then + target("test_string") + set_kind("binary") + + add_files("test/test_string.c") + + add_deps("lae_strings") + + add_packages("cmocka") + + if has_config("asan") then + add_cflags("-fsanitize=address", "-fno-omit-frame-pointer", { force = true }) + + add_ldflags("-fsanitize=address", { force = true }) + end +end