Merge branch 'makefile' into 'main'

Add compiling and testing with Makefile

See merge request redox-os/base!231
This commit is contained in:
Jeremy Soller
2026-04-19 08:41:14 -06:00
7 changed files with 164 additions and 26 deletions
+1
View File
@@ -1,4 +1,5 @@
target/
sysroot/
# Local settings folder for Visual Studio Code
.vscode/
+6 -4
View File
@@ -7,8 +7,7 @@ workflow:
stages:
- build
- cross-build
# TODO?
# - test
- test
fmt:
stage: build
@@ -16,8 +15,6 @@ fmt:
- rustup component add rustfmt
- CHECK_ONLY=1 ./fmt.sh
# TODO: unit tests
x86_64:
stage: build
script:
@@ -38,3 +35,8 @@ riscv64gc:
stage: cross-build
script:
- ./check.sh --arch=riscv64gc
boot:
stage: test
script:
- timeout -s KILL 9m ./check.sh --test
Generated
+16 -16
View File
@@ -1311,6 +1311,22 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
[[package]]
name = "netstack"
version = "0.1.0"
dependencies = [
"anyhow",
"daemon",
"libredox",
"log",
"redox-log",
"redox-scheme",
"redox_event",
"redox_syscall 0.7.4",
"scheme-utils",
"smoltcp",
]
[[package]]
name = "nom"
version = "3.2.1"
@@ -1841,22 +1857,6 @@ dependencies = [
"libredox",
]
[[package]]
name = "redox_netstack"
version = "0.1.0"
dependencies = [
"anyhow",
"daemon",
"libredox",
"log",
"redox-log",
"redox-scheme",
"redox_event",
"redox_syscall 0.7.4",
"scheme-utils",
"smoltcp",
]
[[package]]
name = "redox_syscall"
version = "0.5.18"
+129
View File
@@ -0,0 +1,129 @@
TARGET ?= x86_64-unknown-redox
LINKER ?= $(shell redoxer env which $(shell redoxer env printenv LD))
BOARD ?=
BUILD_TYPE ?= release
BUILD_FLAGS ?= --release
CARGO ?= redoxer
CARGO_HOST ?= env -u CARGO -u RUSTFLAGS cargo
SRC_DIR ?= $(CURDIR)
BUILD_DIR ?= $(shell pwd)
DESTDIR ?= ./sysroot
SYSROOT ?= $(BUILD_DIR)/target/$(TARGET)/sysroot
TARGET_DIR = $(BUILD_DIR)/target/$(TARGET)/$(BUILD_TYPE)
BUILD_FLAGS += --target-dir $(BUILD_DIR)/target
INITFS_BINS = init logd ramfs randd zerod \
acpid fbbootlogd fbcond hwd inputd lived \
pcid pcid-spawner rtcd vesad
INITFS_DRIVERS_BINS = nvmed virtio-blkd virtio-gpud
BASE_BINS = inputd pcid pcid-spawner redoxerd audiod dhcpd ipcd ptyd netstack
DRIVERS_BINS = e1000d ihdad ihdgd ixgbed rtl8139d rtl8168d \
usbctl usbhidd usbhubd usbscsid virtio-netd xhcid
ifneq (,$(filter i586-unknown-redox i686-unknown-redox x86_64-unknown-redox,$(TARGET)))
INITFS_BINS += ps2d
INITFS_DRIVERS_BINS += ahcid ided
DRIVERS_BINS += ac97d sb16d vboxd
endif
ifeq ($(TARGET),aarch64-unknown-redox)
ifeq ($(BOARD),raspi3b)
INITFS_BINS += bcm2835-sdhcid
endif
endif
INITFS_CARGO_ARGS = $(foreach bin,$(INITFS_BINS),-p $(bin))
INITFS_DRIVERS_CARGO_ARGS = $(foreach bin,$(INITFS_DRIVERS_BINS),-p $(bin))
BASE_CARGO_ARGS = $(foreach bin,$(BASE_BINS),-p $(bin))
DRIVERS_CARGO_ARGS = $(foreach bin,$(DRIVERS_BINS),-p $(bin))
.PHONY: all initfs base install install-initfs install-base test
all: initfs base
install: install-initfs install-base
initfs: $(TARGET_DIR)/initfs.img
base: $(TARGET_DIR)/bin.tag
clean:
rm -rf $(SRC_DIR)/target $(SRC_DIR)/sysroot $(SYSROOT) $(TARGET_DIR)
# test if booting
test: all
$(MAKE) install
REDOXER_QEMU_SMP=1 redoxer exec --folder ./sysroot/:/ true
# test with interactive gui
test-gui: all
$(MAKE) install
REDOXER_QEMU_SMP=1 redoxer exec --gui --folder ./sysroot/:/ ion
# -----------------------------------------------------------------------------
# base-initfs
# -----------------------------------------------------------------------------
$(SYSROOT)/bin/redoxfs:
redoxer pkg redoxfs
$(TARGET_DIR)/initfs: $(SYSROOT)/bin/redoxfs
rm -rf "$@" "$@.partial"
# Copy config files
mkdir -p "$@.partial/lib/init.d" "$@.partial/lib/pcid.d"
cp "$(SRC_DIR)/init.initfs.d"/* "$@.partial/lib/init.d/"
cp "$(SRC_DIR)/drivers/initfs.toml" "$@.partial/lib/pcid.d/initfs.toml"
# Build daemons and drivers
CARGO_PROFILE_RELEASE_OPT_LEVEL=s CARGO_PROFILE_RELEASE_PANIC=abort \
$(CARGO) build $(BUILD_FLAGS) \
--manifest-path "$(SRC_DIR)/Cargo.toml" \
$(INITFS_CARGO_ARGS) $(INITFS_DRIVERS_CARGO_ARGS)
# Distribute binaries
mkdir -pv "$@.partial/bin" "$@.partial/lib/drivers"
for bin in $(INITFS_BINS); do \
cp -v "$(TARGET_DIR)/$$bin" "$@.partial/bin"; \
done
for bin in $(INITFS_DRIVERS_BINS); do \
cp -v "$(TARGET_DIR)/$$bin" "$@.partial/lib/drivers"; \
done
cp "$(SYSROOT)/bin/redoxfs" "$@.partial/bin"
mv "$@.partial" "$@"
$(TARGET_DIR)/bootstrap:
cd "$(SRC_DIR)/bootstrap" && $(CARGO) rustc $(BUILD_FLAGS) \
-- -Ctarget-feature=+crt-static -Clinker="$(LINKER)"
$(TARGET_DIR)/initfs.img: $(TARGET_DIR)/initfs $(TARGET_DIR)/bootstrap
$(CARGO_HOST) run --manifest-path "$(SRC_DIR)/initfs/tools/Cargo.toml" --bin redox-initfs-ar -- \
"$(TARGET_DIR)/initfs" "$(TARGET_DIR)/bootstrap" -o "$@"
install-initfs: $(TARGET_DIR)/initfs.img
@mkdir -pv "$(DESTDIR)/usr/lib/boot"
@cp -v "$<" "$(DESTDIR)/usr/lib/boot/initfs"
# -----------------------------------------------------------------------------
# base
# -----------------------------------------------------------------------------
$(TARGET_DIR)/bin.tag:
# Build daemons and drivers
CARGO_PROFILE_RELEASE_OPT_LEVEL=s CARGO_PROFILE_RELEASE_PANIC=abort \
$(CARGO) build $(BUILD_FLAGS) \
--manifest-path "$(SRC_DIR)/Cargo.toml" \
$(BASE_CARGO_ARGS) $(DRIVERS_CARGO_ARGS)
mv $(TARGET_DIR)/smolnetd $(TARGET_DIR)/netstack
touch "$@"
install-base: $(TARGET_DIR)/bin.tag
@mkdir -pv "$(DESTDIR)/usr/bin" "$(DESTDIR)/usr/lib/drivers"
@mkdir -pv "$(DESTDIR)/usr/lib/init.d/" "$(DESTDIR)/usr/lib/pcid.d"
# Distribute binaries
@for bin in $(BASE_BINS); do \
cp -v "$(TARGET_DIR)/$$bin" "$(DESTDIR)/usr/bin"; \
done
@for bin in $(DRIVERS_BINS); do \
cp -v "$(TARGET_DIR)/$$bin" "$(DESTDIR)/usr/lib/drivers"; \
done
@mv -v $(DESTDIR)/usr/bin/netstack $(DESTDIR)/usr/bin/smolnetd
# Copy configurations
@cp -v "$(SRC_DIR)/init.d"/* "$(DESTDIR)/usr/lib/init.d/"
@find "$(SRC_DIR)/drivers" -maxdepth 3 -type f -name 'config.toml' | while read -r conf; do \
driver=$$(basename "$$(dirname "$$conf")"); \
cp -v "$$conf" "$(DESTDIR)/usr/lib/pcid.d/$$driver.toml"; \
done
+8 -2
View File
@@ -32,6 +32,12 @@ To learn how to do development with these system components inside the Redox bui
### How To Build
To build this system component you need to download the Redox build system, you can learn how to do it on the [Building Redox](https://doc.redox-os.org/book/podman-build.html) page.
It is recommended to build this system component via the Redox build system, you can learn how to do it on the [Building Redox](https://doc.redox-os.org/book/podman-build.html) page.
This is necessary because they only work with cross-compilation to a Redox virtual machine or real hardware, but you can do some testing from Linux.
To build and test outside the build system, [install redoxer](https://doc.redox-os.org/book/ci.html) then use `check.sh` script to build or test:
- `./check.sh` - Check build for x86_64
- `./check.sh --arch=ARCH` - Check build for specific ARCH (`aarch64`, `i586`, `riscv64gc`)
- `./check.sh --all` - Check build for all ARCH
- `./check.sh --test` - Check the base system boots up on x86_64
You can also use `make install` to inspect the content on `./sysroot`, or `make test-gui` to test booting with orbital interactively.
+3 -3
View File
@@ -41,7 +41,7 @@ SUPPORTED_TARGETS=(
CURRENT_TARGET="${TARGET:-x86_64-unknown-redox}"
CHECK_ALL=false
CMD_ACTION="check"
CMD_ACTION="all"
while [[ $# -gt 0 ]]; do
case "$1" in
--all-target)
@@ -74,9 +74,9 @@ run_redoxer() {
redoxer toolchain || { echo -e "${RED}Fail: redoxer toolchain for: $target.${NC}" && exit 1; }
echo "----------------------------------------"
echo "Running redoxer $CMD_ACTION for: $TARGET"
echo "Running make $CMD_ACTION for: $TARGET"
if redoxer "$CMD_ACTION"; then
if make "$CMD_ACTION"; then
return 0
else
echo -e "${RED}Fail: $CMD_ACTION $TARGET failed.${NC}"
+1 -1
View File
@@ -1,5 +1,5 @@
[package]
name = "redox_netstack"
name = "netstack"
description = "Network stack daemons"
version = "0.1.0"
edition = "2021"