From 360c5ef64b0446837f461379f45964b9a0d28a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E5=8F=8B=E6=8D=B7?= Date: Thu, 2 May 2024 17:20:37 +0800 Subject: [PATCH] feat: remove axlibc --- .cargo/config.toml | 2 +- .gitignore | 2 -- Cargo.lock | 6 ------ Cargo.toml | 2 +- Makefile | 19 +++++++++++-------- README.md | 11 +++++++++++ crates/axlibc/Cargo.toml | 16 ++++++++++++++++ crates/axlibc/src/lib.rs | 5 +++++ scripts/make/build.mk | 3 +++ scripts/make/build_c.mk | 2 +- scripts/make/build_lwext4.mk | 2 +- 11 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 crates/axlibc/Cargo.toml create mode 100644 crates/axlibc/src/lib.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index 94c20e3..352c5d7 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,4 +1,4 @@ [env] AX_WORK_DIR = { value = ".", relative = true } -AX_LIBC_DIR = { value = "tools/axlibc", relative = true } \ No newline at end of file +AX_LIBC_DIR = { value = "crates/axlibc", relative = true } \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2369bc5..43b1e8d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,4 @@ arceos-fada.bin.gz arceos-fada.itb .tmp_its !tools/rk3588/ramdisk.img -!tools/axlibc linker_* -crates/ \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 00eae8e..574dcd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -166,18 +166,14 @@ name = "arceos_posix_api" version = "0.1.0" source = "git+https://github.com/Starry-OS/arceos_posix_api.git#0949faae5bc4e892035f8c327678c49bfa59f0b5" dependencies = [ - "axalloc", "axconfig", "axerrno", "axfeat", - "axfs", "axhal", "axio", "axlog", - "axnet", "axruntime", "axsync", - "axtask", "bindgen", "flatten_objects", "lazy_static", @@ -317,8 +313,6 @@ dependencies = [ "axruntime", "axsync", "axtask", - "spinlock", - "taskctx", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 5eb672b..162803a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,5 +9,5 @@ lto = true lto = true [workspace] -members = ["tools/axlibc", "apps/display", "apps/exception", "apps/helloworld", "apps/memtest", "apps/fs/shell", "apps/net/echoserver", "apps/net/httpclient", "apps/net/httpserver", "apps/net/udpserver", "apps/net/bwbench", "apps/task/parallel", "apps/task/sleep", "apps/task/yield", "apps/task/priority", "apps/task/tls", "apps/monolithic_userboot"] +members = ["crates/axlibc", "apps/display", "apps/exception", "apps/helloworld", "apps/memtest", "apps/fs/shell", "apps/net/echoserver", "apps/net/httpclient", "apps/net/httpserver", "apps/net/udpserver", "apps/net/bwbench", "apps/task/parallel", "apps/task/sleep", "apps/task/yield", "apps/task/priority", "apps/task/tls", "apps/monolithic_userboot"] resolver = "2" diff --git a/Makefile b/Makefile index 21ac160..496097a 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ SMP ?= 1 MODE ?= release LOG ?= off V ?= - +LIBC_DIR = crates/axlibc # App options A ?= apps/monolithic_userboot APP ?= $(A) @@ -161,12 +161,15 @@ else ifeq ($(PLATFORM_NAME), aarch64-rk3588j) include scripts/make/rk3588.mk endif -make_bin: - ifeq ($(STRUCT), Monolithic) - $(call make_bin) - endif +pre_c: +ifeq ($(wildcard crates/axlibc/include),) + @rm -rf crates/axlibc + @git clone https://github.com/Starry-OS/axlibc.git crates/axlibc + @cargo update axlibc + @echo Load axlibc successfully +endif -build: make_bin $(OUT_DIR) $(OUT_BIN) +build: $(OUT_DIR) $(OUT_BIN) disasm: $(OBJDUMP) $(OUT_ELF) | less @@ -202,7 +205,7 @@ fmt: cargo fmt --all fmt_c: - @clang-format --style=file -i $(shell find tools/axlibc -iname '*.c' -o -iname '*.h') + @clang-format --style=file -i $(shell find crates/axlibc -iname '*.c' -o -iname '*.h') test: $(call app_test) @@ -222,7 +225,7 @@ clean: clean_c cargo clean clean_c:: - rm -rf tools/axlibc/build_* + rm -rf crates/axlibc/build_* rm -rf $(app-objs) .PHONY: all build disasm run justrun debug clippy fmt fmt_c test test_no_fail_fast clean clean_c doc disk_image make_bin diff --git a/README.md b/README.md index d32620d..393ed51 100644 --- a/README.md +++ b/README.md @@ -32,3 +32,14 @@ $ ./build_img.sh x86_64 $ make A=apps/monolithic_userboot ARCH=x86_64 run ``` +## Build C applications + +```sh +# Load axlibc +$ make pre_c + +# Build the application +# $ make A=apps/ ARCH= build +$ make A=apps/c/helloworld ARCH=x86_64 build +``` + diff --git a/crates/axlibc/Cargo.toml b/crates/axlibc/Cargo.toml new file mode 100644 index 0000000..79a169b --- /dev/null +++ b/crates/axlibc/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "axlibc" +version = "0.1.0" +description = "Empty crates mock for cargo analyzer.When you want to use it, first clone it from the github repository." +repository = "https://github.com/Starry-OS/axlibc" + + +[dependencies] +axfeat = { git = "https://github.com/Starry-OS/axfeat.git" } +arceos_posix_api = { git = "https://github.com/Starry-OS/arceos_posix_api.git" } +axio = { git = "https://github.com/Starry-OS/axio.git" } +axerrno = { git = "https://github.com/Starry-OS/axerrno.git" } +arch_boot = { git = "https://github.com/Starry-OS/arch_boot.git" } + +[build-dependencies] +bindgen ={ version = "0.66" } \ No newline at end of file diff --git a/crates/axlibc/src/lib.rs b/crates/axlibc/src/lib.rs new file mode 100644 index 0000000..2b1bcbc --- /dev/null +++ b/crates/axlibc/src/lib.rs @@ -0,0 +1,5 @@ +//! Empty crates mock for cargo analyzer.When you want to use it, first clone it from the github repository. +//! +//! The repository is [here](https://github.com/Starry-OS/axlibc) +#![no_std] +#![no_main] diff --git a/scripts/make/build.mk b/scripts/make/build.mk index 945c1d3..8a57d52 100644 --- a/scripts/make/build.mk +++ b/scripts/make/build.mk @@ -42,6 +42,9 @@ ifeq ($(APP_TYPE), rust) $(call cargo_build,--manifest-path $(APP)/Cargo.toml,$(AX_FEAT) $(LIB_FEAT) $(APP_FEAT)) @cp $(rust_elf) $(OUT_ELF) else ifeq ($(APP_TYPE), c) +ifeq ($(wildcard $(LIBC_DIR)/include),) + $(error "libc" is not built, please build it first by run the command `make pre_c`) +endif $(call cargo_build,-p axlibc,$(AX_FEAT) $(LIB_FEAT)) endif diff --git a/scripts/make/build_c.mk b/scripts/make/build_c.mk index 6230158..3e786d6 100644 --- a/scripts/make/build_c.mk +++ b/scripts/make/build_c.mk @@ -1,7 +1,7 @@ rust_lib_name := axlibc rust_lib := target/$(TARGET)/$(MODE)/lib$(rust_lib_name).a -ulib_dir := tools/axlibc +ulib_dir := crates/axlibc src_dir := $(ulib_dir)/c obj_dir := $(ulib_dir)/build_$(ARCH) inc_dir := $(ulib_dir)/include diff --git a/scripts/make/build_lwext4.mk b/scripts/make/build_lwext4.mk index cdb6709..1162305 100644 --- a/scripts/make/build_lwext4.mk +++ b/scripts/make/build_lwext4.mk @@ -6,7 +6,7 @@ local_lib_feat := fp_simd alloc paging fs fd export LIBC_BUILD_TARGET_DIR=$(abspath $(local_obj_dir)) ### include scripts/make/build_c.mk -local_ulib_dir := tools/axlibc +local_ulib_dir := crates/axlibc local_src_dir := $(local_ulib_dir)/c local_inc_dir := $(local_ulib_dir)/include local_obj_dir := $(local_ulib_dir)/lwext4_libc_$(ARCH)