Separate component building from copying for better architecture

- Remove component copying from build functions (build_zinit, build_rfs, etc)
- Add initramfs_copy_components() function to copy built components to initramfs
- Add components_copy stage between init_script and modules_setup
- Fix components_verify to check built components (not initramfs locations)
- Now supports partial builds: build components separately, copy later
- All 4 components (zinit 8.1M, rfs 13M, mycelium 21M, corex 4.0M) working
This commit is contained in:
2025-09-03 20:18:21 +02:00
parent 55d9133b3a
commit b4b6284f6d
3 changed files with 113 additions and 47 deletions

View File

@@ -291,13 +291,8 @@ function build_zinit() {
return 1
fi
# Install to initramfs
safe_mkdir "${INSTALL_DIR}/sbin"
safe_execute cp "$binary_path" "${INSTALL_DIR}/sbin/zinit"
safe_execute chmod +x "${INSTALL_DIR}/sbin/zinit"
local binary_size=$(get_file_size "${INSTALL_DIR}/sbin/zinit")
log_info "Installed zinit binary (${binary_size}) to: ${INSTALL_DIR}/sbin/zinit"
local binary_size=$(get_file_size "$binary_path")
log_info "Built zinit binary (${binary_size}) at: ${binary_path}"
}
# Build function for rfs (standard Rust build)
@@ -343,13 +338,8 @@ function build_rfs() {
return 1
fi
# Install to initramfs
safe_mkdir "${INSTALL_DIR}/usr/bin"
safe_execute cp "$binary_path" "${INSTALL_DIR}/usr/bin/rfs"
safe_execute chmod +x "${INSTALL_DIR}/usr/bin/rfs"
local binary_size=$(get_file_size "${INSTALL_DIR}/usr/bin/rfs")
log_info "Installed rfs binary (${binary_size}) to: ${INSTALL_DIR}/usr/bin/rfs"
local binary_size=$(get_file_size "$binary_path")
log_info "Built rfs binary (${binary_size}) at: ${binary_path}"
}
# Build function for mycelium (special subdirectory build)
@@ -388,13 +378,8 @@ function build_mycelium() {
return 1
fi
# Install to initramfs
safe_mkdir "${INSTALL_DIR}/usr/bin"
safe_execute cp "$binary_path" "${INSTALL_DIR}/usr/bin/mycelium"
safe_execute chmod +x "${INSTALL_DIR}/usr/bin/mycelium"
local binary_size=$(get_file_size "${INSTALL_DIR}/usr/bin/mycelium")
log_info "Installed mycelium binary (${binary_size}) to: ${INSTALL_DIR}/usr/bin/mycelium"
local binary_size=$(get_file_size "$binary_path")
log_info "Built mycelium binary (${binary_size}) at: ${binary_path}"
}
# Install function for rfs (pre-built binary)
@@ -413,14 +398,11 @@ function install_rfs() {
return 1
fi
# Make executable and install
# Make executable
safe_execute chmod +x "$binary_path"
safe_mkdir "${INSTALL_DIR}/usr/bin"
safe_execute cp "$binary_path" "${INSTALL_DIR}/usr/bin/rfs"
safe_execute chmod +x "${INSTALL_DIR}/usr/bin/rfs"
local binary_size=$(get_file_size "${INSTALL_DIR}/usr/bin/rfs")
log_info "Installed rfs binary (${binary_size}) to: ${INSTALL_DIR}/usr/bin/rfs"
local binary_size=$(get_file_size "$binary_path")
log_info "Prepared rfs binary (${binary_size}) at: ${binary_path}"
}
# Install function for corex (pre-built binary)
@@ -443,37 +425,34 @@ function install_corex() {
return 1
fi
# Make executable and install
# Make executable
safe_execute chmod +x "$binary_path"
safe_mkdir "${INSTALL_DIR}/usr/bin"
safe_execute cp "$binary_path" "${INSTALL_DIR}/usr/bin/corex"
safe_execute chmod +x "${INSTALL_DIR}/usr/bin/corex"
local binary_size=$(get_file_size "${INSTALL_DIR}/usr/bin/corex")
log_info "Installed corex binary (${binary_size}) to: ${INSTALL_DIR}/usr/bin/corex"
local binary_size=$(get_file_size "$binary_path")
log_info "Prepared corex binary (${binary_size}) at: ${binary_path}"
}
# Verify all built components
# Verify all components are built (not copied to initramfs yet)
function components_verify_installation() {
local install_dir="${INSTALL_DIR:-${PROJECT_ROOT}/initramfs}"
local components_dir="${COMPONENTS_DIR:-${PROJECT_ROOT}/components}"
section_header "Verifying Component Installation"
section_header "Verifying Component Build"
# List of expected binaries and their locations
# List of expected built binaries and their locations in components directory
local expected_binaries=(
"sbin/zinit"
"usr/bin/rfs"
"usr/bin/mycelium"
"usr/bin/corex"
"zinit/target/x86_64-unknown-linux-musl/release/zinit"
"rfs/rfs"
"mycelium/myceliumd/target/x86_64-unknown-linux-musl/release/mycelium"
"corex/corex"
)
local missing_count=0
for binary in "${expected_binaries[@]}"; do
local full_path="${install_dir}/${binary}"
local full_path="${components_dir}/${binary}"
if [[ -f "$full_path" && -x "$full_path" ]]; then
local size=$(get_file_size "$full_path")
log_info "${binary} (${size})"
log_info " Built ${binary##*/} (${size}) at: ${binary}"
else
log_error "✗ Missing or not executable: ${binary}"
((missing_count++))
@@ -481,10 +460,10 @@ function components_verify_installation() {
done
if [[ $missing_count -eq 0 ]]; then
log_info "All components installed successfully"
log_info "All components built successfully"
return 0
else
log_error "${missing_count} components missing or invalid"
log_error "${missing_count} components missing or failed to build"
return 1
fi
}