Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 36 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
# VoidFrame CMake Build Script - v0.0.2-development3
# ============================================================================
cmake_minimum_required(VERSION 3.30)
project(VoidFrame VERSION 0.0.2 LANGUAGES C CXX ASM_NASM)
project(VoidFrame
VERSION 0.0.2
LANGUAGES C CXX ASM_NASM
HOMEPAGE_URL "https://github.com/assembler-0/VoidFrame"
DESCRIPTION "A hobbyist operating system kernel written in C and Rust"
)
enable_language(ASM_NASM)

# ============================================================================
Expand All @@ -16,6 +21,7 @@ include(dependencies)
include(flags)
include(configuration)
include(source)
include(rust_utils)

# ============================================================================
# Platform Checks
Expand Down Expand Up @@ -44,6 +50,7 @@ endif()

if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
message(STATUS "CMake: Target Architecture: ${CMAKE_SYSTEM_PROCESSOR}")
set(Rust_CARGO_TARGET "x86_64-unknown-none")
else()
message(FATAL_ERROR "Unsupported target architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
Expand All @@ -67,15 +74,28 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# ============================================================================
# Rust Memory Management
# ============================================================================
add_subdirectory(mm/rust)
add_subdirectory(kernel/atomic/rust)
# ============================================================================
# Manifest paths for Rust components (corrosion with CMake)
# ============================================================================
set(RUST_HEAP_MANIFEST_PATH "${CMAKE_SOURCE_DIR}/mm/rust/Cargo.toml")
set(RUST_ATOMIC_MANIFEST_PATH "${CMAKE_SOURCE_DIR}/kernel/atomic/rust/Cargo.toml")

# ============================================================================
# Corrosion
# ============================================================================
add_subdirectory(corrosion)
corrosion_import_crate(
MANIFEST_PATH ${RUST_HEAP_MANIFEST_PATH}
NO_STD
)
corrosion_import_crate(
MANIFEST_PATH ${RUST_ATOMIC_MANIFEST_PATH}
NO_STD
)

# ============================================================================
# ============================================================================
# Build Include Directories
# ============================================================================
# ============================================================================
include_directories(
.
include
Expand Down Expand Up @@ -116,9 +136,9 @@ include_directories(
arch/x86_64/syscall
)

# ============================================================================
# ============================================================================
# Kernel Linking
# ============================================================================
# ============================================================================
add_executable(voidframe.krnl
${C_SOURCES}
${CPP_SOURCES}
Expand All @@ -131,26 +151,26 @@ if(NOT EXCLUDE_EXTRA_OBJECTS)
endif()

# Rust libraries
target_link_libraries(voidframe.krnl PRIVATE rust_heap)
target_link_libraries(voidframe.krnl PRIVATE rust_spinlock)
link_rust_library(voidframe.krnl voidframe-spinlock)
link_rust_library(voidframe.krnl voidframe-mm)

# Configure the linker to use ld.lld with proper arguments
set_target_properties(voidframe.krnl PROPERTIES
LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/voidframe.ld"
)

# Set linker flags for this specific target
target_link_options(voidframe.krnl PRIVATE
target_link_options(voidframe.krnl PRIVATE
-fuse-ld=lld
-T ${CMAKE_CURRENT_SOURCE_DIR}/voidframe.ld
-nostdlib
-static
-Wl,-melf_x86_64
)

# ============================================================================
# ============================================================================
# ISO Creation
# ============================================================================
# ============================================================================
add_custom_command(
OUTPUT VoidFrame.iso
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/isodir/boot/grub
Expand Down Expand Up @@ -230,4 +250,4 @@ add_custom_target(dump
COMMAND ${LLVM_OBJDUMP} -t $<TARGET_FILE:voidframe.krnl> > voidframe.sym
DEPENDS voidframe.krnl
COMMENT "Generating disassembly and symbols"
)
)
9 changes: 9 additions & 0 deletions cmake/rust_utils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ============================================================================
# Rust Utilities for CMake
# ============================================================================

# Function to link Rust libraries with automatic hyphen-to-underscore conversion
function(link_rust_library target_name rust_lib_name)
string(REPLACE "-" "_" converted_name "${rust_lib_name}")
target_link_libraries(${target_name} PRIVATE ${converted_name})
endfunction()
2 changes: 1 addition & 1 deletion cmake/variable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ add_compile_definitions(
KERNEL_SPACE_END=0xFFFFFFFFFFFFFFFFULL
PREFETCH_DISTANCE=256
NT_STORE_THRESHOLD=4*1024*1024
MAX_SUPPORTED_MEMORY=128*1024*1024*1024
MAX_SUPPORTED_MEMORY=128ULL*1024*1024*1024
)
8 changes: 8 additions & 0 deletions corrosion/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

**/target/
**/*.rs.bk
build*/
.vscode
.idea
cmake-build-*
test/test_header.cmake
86 changes: 86 additions & 0 deletions corrosion/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
cmake_minimum_required(VERSION 3.22)
project(Corrosion
# Official releases will be major.minor.patch. When the `tweak` field is
# set it indicates that we are on a commit, that is not a officially
# tagged release. Users don't need to care about this, it is mainly to
# clearly see in configure logs which version was used, without needing to
# rely on `git`, since Corrosion may be installed or otherwise packaged.
VERSION 0.99.99 # 1.0-pre-release
LANGUAGES NONE
HOMEPAGE_URL "https://corrosion-rs.github.io/corrosion/"
)

# ==== Corrosion Configuration ====

option(
CORROSION_BUILD_TESTS
"Build Corrosion test project"
${PROJECT_IS_TOP_LEVEL}
)

if (PROJECT_IS_TOP_LEVEL)
# We need to enable a language for corrosions test to work.
# For projects using corrosion this is not needed
enable_language(C)
endif()

# This little bit self-hosts the Corrosion toolchain to build the generator
# tool.
#
# It is strongly encouraged to install Corrosion separately and use
# `find_package(Corrosion REQUIRED)` instead if that works with your workflow.
option(CORROSION_INSTALL_ONLY "Only add rules for installing Corrosion itself." OFF)
if (NOT CORROSION_INSTALL_ONLY)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(Corrosion)
endif()

# Testing
if (CORROSION_BUILD_TESTS)
include(CTest)
add_subdirectory(test)
endif()

# If Corrosion is a subdirectory, do not enable its install code
if (NOT PROJECT_IS_TOP_LEVEL)
return()
endif()

# Installation

include(GNUInstallDirs)

# Generate the Config file
include(CMakePackageConfigHelpers)

configure_package_config_file(
cmake/CorrosionConfig.cmake.in CorrosionConfig.cmake
INSTALL_DESTINATION
"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/Corrosion"
)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY
SameMajorVersion
ARCH_INDEPENDENT
)

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfigVersion.cmake"
DESTINATION
"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/Corrosion"
)

# These CMake scripts are needed both for the install and as a subdirectory
install(
FILES
cmake/Corrosion.cmake
cmake/CorrosionGenerator.cmake
cmake/FindRust.cmake
DESTINATION
"${CMAKE_INSTALL_FULL_DATADIR}/cmake"
)
Loading