Skip to content

Commit

Permalink
解决设置rust workspace带来的“工具链不一致”的问题 (#345)
Browse files Browse the repository at this point in the history
更改workflow
  • Loading branch information
fslongjin authored Aug 26, 2023
1 parent 9a367aa commit e92d022
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 22 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/rustfmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,5 @@ jobs:
printf "\n" >> user/libs/libc/src/include/internal/bindings/bindings.rs
- name: Check format
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
run: |
FMT_CHECK=1 make fmt
7 changes: 0 additions & 7 deletions Cargo.toml

This file was deleted.

15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ export NM=$(DragonOS_GCC)/x86_64-elf-nm
export AR=$(DragonOS_GCC)/x86_64-elf-ar
export OBJCOPY=$(DragonOS_GCC)/x86_64-elf-objcopy

# 检查是否需要进行fmt --check
# 解析命令行参数
FMT_CHECK?=0

ifeq ($(FMT_CHECK), 1)
FMT_CHECK=--check
else
FMT_CHECK=
endif


.PHONY: all
all: kernel user
Expand Down Expand Up @@ -142,6 +152,11 @@ run-docker:
$(MAKE) write_diskimage || exit 1
$(MAKE) qemu

fmt:
@echo "格式化代码"
FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C kernel
FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C user

help:
@echo "编译:"
@echo " make all -j <n> - 本地编译,不运行,n为要用于编译的CPU核心数"
Expand Down
1 change: 1 addition & 0 deletions docs/introduction/build_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ make run-docker
- 清理编译产生的文件: `make clean`
- 编译文档: `make docs` (需要手动安装sphinx以及docs下的`requirements.txt`中的依赖)
- 清理文档: `make clean-docs`
- 格式化代码: `make fmt`

:::{note}
如果您需要在vnc中运行DragonOS,请在上述命令后加上`-vnc`后缀。如:`make run-vnc`
Expand Down
6 changes: 5 additions & 1 deletion kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ all:

clean:
rm -f Cargo.lock
$(MAKE) -C src clean
$(MAKE) -C src clean

.PHONY: fmt
fmt:
cargo fmt --all $(FMT_CHECK)
4 changes: 2 additions & 2 deletions kernel/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ kernel_rust:
all: kernel

@echo "Linking kernel..."
$(LD) -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") $(ROOT_PATH)/target/x86_64-unknown-none/release/libdragonos_kernel.a -T link.lds
$(LD) -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a -T link.lds
# 生成kallsyms
current_dir=$(pwd)

Expand All @@ -55,7 +55,7 @@ all: kernel
# 重新链接
@echo "Re-Linking kernel..."
@echo $(shell find . -name "*.o")
$(LD) -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") $(ROOT_PATH)/target/x86_64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o -T link.lds
$(LD) -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o -T link.lds
@echo "Generating kernel ELF file..."
# 生成内核文件
$(OBJCOPY) -I elf64-x86-64 -O elf64-x86-64 kernel ../../bin/kernel/kernel.elf
Expand Down
3 changes: 0 additions & 3 deletions rust-toolchain.toml

This file was deleted.

8 changes: 6 additions & 2 deletions user/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ sys_api_lib: sys_api_lib_stage_1
mkdir -p $(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp
mkdir -p $(OLD_LIBC_INSTALL_PATH)/include
mkdir -p $(OLD_LIBC_INSTALL_PATH)/lib
$(AR) x $(ROOT_PATH)/target/x86_64-unknown-none/release/liblibc.a --output=$(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp
$(AR) x libs/libc/target/x86_64-unknown-none/release/liblibc.a --output=$(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp
$(AR) crvs $(OLD_LIBC_INSTALL_PATH)/lib/libc.a $(shell find ./libs/* -name "*.o") $(shell find $(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp/* -name "*.o")
rm -rf $(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp
# $(shell find ./libs/* -name "*.o" | xargs -I {} cp {} $(ROOT_PATH)/bin/sysroot/usr/lib/)
Expand All @@ -112,4 +112,8 @@ clean:
cd $$subdir && $(MAKE) clean;\
cd .. ;\
done


.PHONY: fmt
fmt:
FMT_CHECK=$(FMT_CHECK) $(MAKE) -C libs
FMT_CHECK=$(FMT_CHECK) $(MAKE) -C apps
5 changes: 4 additions & 1 deletion user/apps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ $(user_apps_sub_dirs): ECHO
$(MAKE) -C $@ all CFLAGS="$(CFLAGS)" tmp_output_dir="$(tmp_output_dir)" output_dir="$(output_dir)" sys_libs_dir="$(sys_libs_dir)"

all: $(user_apps_sub_dirs)


.PHONY: clean
fmt:
@echo "格式化代码: user/apps"
7 changes: 6 additions & 1 deletion user/libs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ clean:
echo "Clean in dir: $$subdir";\
cd $$subdir && $(MAKE) clean;\
cd .. ;\
done
done

.PHONY: clean
fmt:
@echo "格式化代码: user/libs"
FMT_CHECK=$(FMT_CHECK) $(MAKE) -C libc fmt
6 changes: 5 additions & 1 deletion user/libs/libc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ all:

clean:
rm -f Cargo.lock
$(MAKE) -C src clean
$(MAKE) -C src clean

.PHONY: fmt
fmt:
cargo fmt --all $(FMT_CHECK)

0 comments on commit e92d022

Please sign in to comment.