summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-02-24 11:43:13 +1100
committerOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-02-24 11:43:13 +1100
commitb047be5252aeb981faea077409c1768fda0301d9 (patch)
tree43925d4f4ef3aed59a147746d918c34e66fe91a6
parenta67df4d18655e58d8544e91cde546122f41cb492 (diff)
xmake init with shared/static lib
-rw-r--r--.clang-format7
-rw-r--r--.gitignore9
-rw-r--r--examples/first.c9
-rw-r--r--src/defines.h44
-rw-r--r--src/platform/file.c29
-rw-r--r--src/platform/file.h11
-rw-r--r--xmake.lua40
7 files changed, 149 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..441b1d8
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,7 @@
+---
+Language: Cpp
+BasedOnStyle: Google
+ColumnLimit: 100
+Cpp11BracedListStyle: false # {.x = 1.0, .y = 2.0} -> { .x = 1.0, .y = 2.0 }
+IncludeBlocks: Preserve # sort each block of include statements instead of all
+...
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f082afc
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,9 @@
+_build
+build
+_temp
+.xmake
+.vscode
+.cache
+.clangd
+compile_commands.json
+node_modules/ \ No newline at end of file
diff --git a/examples/first.c b/examples/first.c
new file mode 100644
index 0000000..0f61a51
--- /dev/null
+++ b/examples/first.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+#include "defines.h"
+
+int main() {
+ i32 num = -256;
+ printf("A number: %d\n", num);
+
+ return 0;
+} \ No newline at end of file
diff --git a/src/defines.h b/src/defines.h
new file mode 100644
index 0000000..2129d94
--- /dev/null
+++ b/src/defines.h
@@ -0,0 +1,44 @@
+/**
+ * @file defines.h
+ * @author your name (you@domain.com)
+ * @brief
+ * @date 2024-02-24
+ * @copyright Copyright (c) 2024
+ */
+#pragma once
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef uint64_t u64;
+
+typedef int8_t i8;
+typedef int16_t i16;
+typedef int32_t i32;
+typedef int64_t i64;
+
+typedef float f32;
+typedef double f64;
+
+_Static_assert(sizeof(bool) == 1, "type bool should be 1 byte");
+
+_Static_assert(sizeof(u8) == 1, "type u8 should be 1 byte");
+_Static_assert(sizeof(u16) == 2, "type u16 should be 2 byte");
+_Static_assert(sizeof(u32) == 4, "type u32 should be 4 byte");
+_Static_assert(sizeof(u64) == 8, "type u64 should be 8 byte");
+
+_Static_assert(sizeof(i8) == 1, "type i8 should be 1 byte");
+_Static_assert(sizeof(i16) == 2, "type i16 should be 2 byte");
+_Static_assert(sizeof(i32) == 4, "type i32 should be 4 byte");
+_Static_assert(sizeof(i64) == 8, "type i64 should be 8 byte");
+
+_Static_assert(sizeof(f32) == 4, "type f32 should be 4 bytes");
+_Static_assert(sizeof(f64) == 8, "type f64 should be 8 bytes");
+
+_Static_assert(sizeof(ptrdiff_t) == 8, "");
+
+#define alignof(x) _Alignof(x) \ No newline at end of file
diff --git a/src/platform/file.c b/src/platform/file.c
new file mode 100644
index 0000000..497a95c
--- /dev/null
+++ b/src/platform/file.c
@@ -0,0 +1,29 @@
+#include "file.h"
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+const char *string_from_file(const char *path) {
+ FILE *f = fopen(path, "rb");
+ if (f == NULL) {
+ // ERROR("Error reading file: %s. errno: %d", path, errno);
+ return NULL;
+ }
+ if (ferror(f)) {
+ // ERROR("Error reading file: %s. errno: %d", path, errno);
+ return NULL;
+ }
+ fseek(f, 0, SEEK_END);
+ long fsize = ftell(f);
+ rewind(f);
+
+ char *string = malloc(fsize + 1);
+ fread(string, fsize, 1, f);
+ fclose(f);
+
+ string[fsize] = '\0';
+
+ return string;
+} \ No newline at end of file
diff --git a/src/platform/file.h b/src/platform/file.h
new file mode 100644
index 0000000..b965ceb
--- /dev/null
+++ b/src/platform/file.h
@@ -0,0 +1,11 @@
+/**
+ * @file file.h
+ * @brief File I/O utilities
+ * @date 2024-02-24
+ * @copyright Copyright (c) 2024
+ */
+#pragma once
+
+#include <stdbool.h>
+
+const char* string_from_file(const char* path);
diff --git a/xmake.lua b/xmake.lua
new file mode 100644
index 0000000..5a873f0
--- /dev/null
+++ b/xmake.lua
@@ -0,0 +1,40 @@
+set_project("celeritas")
+set_version("0.1.0")
+set_config("cc", "gcc")
+
+add_rules("mode.debug", "mode.release") -- we have two modes: debug & release
+
+-- -Wall : base set of warnings
+-- -Wextra : additional warnings not covered by -Wall
+-- -Wundef : undefined macros
+-- -Wdouble-promotion : catch implicit converion of float to double
+add_cflags("-Wall", "-Wextra", "-Wundef", "-Wdouble-promotion")
+
+if is_mode("debug") then
+ add_cflags("-g") -- Add debug symbols in debug mode
+end
+
+-- common configuration for both static and shared libraries
+target("core_config")
+ set_kind("static") -- kind is required but you can ignore it since it's just for common settings
+ add_includedirs("src/", {public = true})
+ add_includedirs("src/platform/", {public = true})
+ add_files("src/platform/*.c")
+ set_default(false) -- prevents standalone building of this target
+
+-- Define a static library
+target("core_static")
+ set_kind("static")
+ add_deps("core_config") -- inherit common configurations
+
+-- Define a shared library
+target("core_shared")
+ set_kind("shared")
+ add_deps("core_config") -- inherit common configurations
+
+
+target("first")
+ set_kind("binary")
+ add_deps("core_shared")
+ add_files("examples/first.c")
+ set_rundir("$(projectdir)") \ No newline at end of file