feat(build): added basic build system with hallocy library

This commit is contained in:
Mineplay 2025-04-19 11:15:18 -05:00
parent bbc088b123
commit d8cc4b78a7
9 changed files with 227 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
Build

36
CMakeLists.txt Normal file
View file

@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 3.10)
project(Fledasty C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(LIB_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/Lib/Include")
if(WIN32)
set (HALLOCY_LIB_PATH "${CMAKE_SOURCE_DIR}/Lib/Windows/Hallocy.lib")
elseif(UNIX)
set (HALLOCY_LIB_PATH "${CMAKE_SOURCE_DIR}/Lib/Linux/libHallocy.a")
endif()
include_directories(${PROJECT_SOURCE_DIR}/Include)
include_directories(${LIB_INCLUDE_DIR})
file(GLOB_RECURSE SRC_FILES "${PROJECT_SOURCE_DIR}/Src/*.c")
add_library(Fledasty STATIC ${SRC_FILES})
add_executable(FledastyTest ${PROJECT_SOURCE_DIR}/Tests/Main.c)
target_link_libraries(Fledasty PRIVATE ${HALLOCY_LIB_PATH})
target_include_directories(FledastyTest PRIVATE ${PROJECT_SOURCE_DIR}/Tests)
target_link_libraries(FledastyTest Fledasty)
if (MSVC)
target_compile_options(Fledasty PRIVATE /W4 /Zl)
else()
target_compile_options(Fledasty PRIVATE -mavx512f -mavx512vl)
target_compile_options(FledastyTest PRIVATE -mavx512f -mavx512vl)
target_compile_options(Fledasty PRIVATE -march=native)
target_compile_options(FledastyTest PRIVATE -march=native)
target_compile_options(Fledasty PRIVATE -Wall -Wextra -pedantic)
endif()

View file

@ -0,0 +1,38 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* -----------------------------------------------------------------------------
* File: Allocator.h
* Description:
* This file contains the functions for allocating, freeing and managing memory.
* It includes functions to allocate, reallocate, free, copy, move and set memory.
*
* Author: Mineplay
* -----------------------------------------------------------------------------
*/
#ifndef HALLOCY_ALLOCATOR
#define HALLOCY_ALLOCATOR
#include <stddef.h>
#include <stdbool.h>
#include "../Utils/Error.h"
void *hallocy_allocate(const size_t size, const bool zero_memory);
static inline void *hallocy_malloc(const size_t size) { return hallocy_allocate(size, false); }
static inline void *hallocy_calloc(const size_t size, size_t count) { return hallocy_allocate(size * count, true); }
void *hallocy_realloc(void *memory_pointer, const size_t size);
HallocyError hallocy_free(void *pointer);
#endif

View file

@ -0,0 +1,36 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* -----------------------------------------------------------------------------
* File: Memory.h
* Description:
* This file implements the functions for managing memory. It includes functions
* to copy, move, compare and set memory.
*
* Author: Mineplay
* -----------------------------------------------------------------------------
*/
#ifndef HALLOCY_MEMORY
#define HALLOCY_MEMORY
#include <stddef.h>
#include <stdbool.h>
#include "../Utils/Error.h"
HallocyError hallocy_set_memory(void *destination, int value, const size_t size);
HallocyError hallocy_copy_memory(void *destination, void *source, const size_t size);
HallocyError hallocy_move_memory(void *destination, void *source, const size_t size);
bool hallocy_compare_memory(void *left_side, void *right_side, const size_t size);
#endif

View file

@ -0,0 +1,34 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* -----------------------------------------------------------------------------
* File: Error.h
* Description:
* This file contains the ErrorCode enum that defines the error codes for the
* library.
*
* Author: Mineplay
* -----------------------------------------------------------------------------
*/
#ifndef HALLOCY_ERROR
#define HALLOCY_ERROR
typedef enum {
HALLOCY_ERROR_NONE = 0,
HALLOCY_ERROR_INVALID_POINTER = 1,
HALLOCY_ERROR_OUT_OF_MEMORY = 2,
HALLOCY_ERROR_UNKNOWN = 3,
HALLOCY_ERROR_INVALID_PARAM = 4
} HallocyError;
#endif

View file

@ -0,0 +1,55 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* -----------------------------------------------------------------------------
* File: Simd.h
* Description:
* This file implements the functions for detecting SIMD support and defines the
* enum for specifing the SIMD type.
*
* Author: Mineplay
* -----------------------------------------------------------------------------
*/
#ifndef HALLOCY_SIMD
#define HALLOCY_SIMD
#if defined(_MSC_VER)
#if defined(_M_ARM64)
#include <arm64intr.h>
#else
#include <intrin.h>
#endif
#else
#if defined(__aarch64__)
#include <arm64intr.h>
#elif defined(__arm__)
#include <arm_neon.h>
#else
#include <immintrin.h>
#endif
#endif
typedef enum {
HALLOCY_SIMD_UNDEFINED = 0,
HALLOCY_SIMD_NONE = 1,
HALLOCY_SIMD_SSE = 2,
HALLOCY_SIMD_SSE2 = 3,
HALLOCY_SIMD_AVX = 4,
HALLOCY_SIMD_AVX2 = 5,
HALLOCY_SIMD_AVX512 = 6,
HALLOCY_SIMD_NEON = 7
} HallocySimdType;
HallocySimdType hallocy_is_simd_supported();
#endif

BIN
Lib/Linux/libHallocy.a Normal file

Binary file not shown.

BIN
Lib/Windows/Hallocy.lib Normal file

Binary file not shown.

27
Tests/Main.c Normal file
View file

@ -0,0 +1,27 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* -----------------------------------------------------------------------------
* File: Main.c
* Description:
* Executes all tests.
*
* Author: Mineplay
* -----------------------------------------------------------------------------
*/
#include <stdio.h>
int main() {
printf("Test\n");
return 0;
}