Skip to content

Commit e06f7fa

Browse files
committed
Fixed Missing Kernel Artifact
1 parent 6d30ef1 commit e06f7fa

3 files changed

Lines changed: 104 additions & 13 deletions

File tree

.github/workflows/cmake.yml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,35 @@ jobs:
2626
libgcc-s1-i386-cross \
2727
wget
2828
29+
- name: Cache AI Model
30+
id: cache-model
31+
uses: actions/cache@v4
32+
with:
33+
path: assets/smollm2.gguf
34+
key: ${{ runner.os }}-model-smollm2
35+
2936
- name: Download AI Model Asset
37+
if: steps.cache-model.outputs.cache-hit != 'true'
3038
run: |
3139
mkdir -p assets
32-
if [ ! -f assets/smollm2.gguf ]; then
33-
wget -O assets/smollm2.gguf https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf
34-
fi
40+
wget -O assets/smollm2.gguf https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf
41+
42+
- name: Configure CMake
43+
run: |
44+
cmake -B build \
45+
-DCMAKE_C_COMPILER=i686-linux-gnu-gcc \
46+
-DCMAKE_ASM_NASM_COMPILER=nasm \
47+
-DCMAKE_BUILD_TYPE=Release
3548
3649
- name: Build BasicallyLinux
3750
run: |
38-
mkdir -p bin
39-
mkdir -p build
40-
# We use GCC as the linker wrapper to automatically locate libgcc.a
41-
# This solves the __udivdi3 and __divdi3 errors
42-
make CC=i686-linux-gnu-gcc \
43-
LD=i686-linux-gnu-gcc \
44-
AS=nasm
51+
cmake --build build
4552
4653
- name: Archive Artifacts
4754
if: success()
4855
uses: actions/upload-artifact@v4
4956
with:
5057
name: basicallylinux-alpha
5158
path: |
52-
kernel.bin
59+
build/kernel.bin
5360
assets/smollm2.gguf

CMakeLists.txt

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(BasicallyLinux C ASM_NASM)
3+
4+
# Enable NASM support
5+
enable_language(ASM_NASM)
6+
7+
# Toolchain configuration (can be overridden by command line)
8+
set(CMAKE_C_COMPILER i686-linux-gnu-gcc)
9+
set(CMAKE_ASM_NASM_COMPILER nasm)
10+
11+
# Compilation flags
12+
add_compile_options(
13+
-ffreestanding
14+
-O2
15+
-Wall
16+
-Wextra
17+
-m32
18+
-fno-pie
19+
-fno-PIC
20+
-fno-stack-protector
21+
-nostdlib
22+
-nostdinc
23+
-msse
24+
-msse2
25+
)
26+
27+
include_directories(include)
28+
29+
# Source discovery
30+
file(GLOB_RECURSE ASM_SOURCES "src/*.s")
31+
file(GLOB_RECURSE C_SOURCES "src/*.c")
32+
33+
# Exclude specific files if needed
34+
list(FILTER C_SOURCES EXCLUDE REGEX "src/drivers/vga.c")
35+
36+
# Handle AI Model Blob
37+
set(ASSETS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/assets")
38+
set(MODEL_BLOB "")
39+
40+
# Check for model candidates
41+
set(CANDIDATES
42+
"${ASSETS_DIR}/smollm2.gguf"
43+
"${ASSETS_DIR}/smollm-135m.gguf"
44+
"${ASSETS_DIR}/SmolLM2-135M-Instruct-Q4_K_M.gguf"
45+
)
46+
47+
foreach(CANDIDATE ${CANDIDATES})
48+
if(EXISTS "${CANDIDATE}")
49+
set(MODEL_BLOB "${CANDIDATE}")
50+
message(STATUS "Found AI model blob: ${MODEL_BLOB}")
51+
break()
52+
endif()
53+
endforeach()
54+
55+
if(MODEL_BLOB)
56+
set(MODEL_OBJ "${CMAKE_CURRENT_BINARY_DIR}/model.o")
57+
add_custom_command(
58+
OUTPUT ${MODEL_OBJ}
59+
COMMAND i686-linux-gnu-objcopy -I binary -O elf32-i386 -B i386
60+
--rename-section .data=.ai_model,alloc,load,readonly,data,contents
61+
"${MODEL_BLOB}" "${MODEL_OBJ}"
62+
DEPENDS "${MODEL_BLOB}"
63+
COMMENT "Converting AI model blob to object file"
64+
)
65+
# Add the object file to the sources
66+
list(APPEND ASM_SOURCES ${MODEL_OBJ})
67+
else()
68+
message(WARNING "AI model blob not found. Kernel will be built without AI support.")
69+
endif()
70+
71+
# Build Kernel Binary
72+
set(LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/linker.ld")
73+
74+
# We use add_executable but we need to control the linking process
75+
add_executable(kernel.bin ${ASM_SOURCES} ${C_SOURCES})
76+
77+
set_target_properties(kernel.bin PROPERTIES
78+
LINK_FLAGS "-T \"${LINKER_SCRIPT}\" -nostdlib -m32 -no-pie -Wl,-z,noexecstack"
79+
SUFFIX ""
80+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
81+
)
82+
83+
# Link with libgcc for arithmetic operations
84+
target_link_libraries(kernel.bin gcc)

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LDFLAGS := -T linker.ld -nostdlib -m32 -no-pie -Wl,-z,noexecstack
99

1010
SRC_DIR := src
1111
BUILD_DIR := build
12-
MODEL_BLOB := $(firstword $(wildcard assets/smollm-135m.gguf) $(wildcard assets/SmolLM2-135M-Instruct-Q4_K_M.gguf))
12+
MODEL_BLOB := $(firstword $(wildcard assets/smollm2.gguf) $(wildcard assets/smollm-135m.gguf) $(wildcard assets/SmolLM2-135M-Instruct-Q4_K_M.gguf))
1313
MODEL_OBJ := $(BUILD_DIR)/model.o
1414

1515
ASM_SRCS := $(shell find $(SRC_DIR) -name "*.s")
@@ -40,7 +40,7 @@ $(BUILD_DIR)/%.c.o: $(SRC_DIR)/%.c
4040
$(CC) $(CFLAGS) -c $< -o $@
4141

4242
kernel.bin: $(OBJS) linker.ld
43-
$(LD) $(LDFLAGS) $(OBJS) -lgcc
43+
$(LD) $(LDFLAGS) -o $@ $(OBJS) -lgcc
4444

4545
$(MODEL_OBJ): $(MODEL_BLOB)
4646
mkdir -p $(dir $@)

0 commit comments

Comments
 (0)