浏览代码

修改Makefile,以使用linux-gun工具链 (#1)

* 修改Makefile,以使用linux-gun工具链

* 添加rustflags

---------

Co-authored-by: longjin <longjin@RinGoTek.cn>
yuyi2439 1 年之前
父节点
当前提交
47e94c0b97
共有 2 个文件被更改,包括 32 次插入19 次删除
  1. 0 2
      .cargo/config.toml
  2. 32 17
      Makefile

+ 0 - 2
.cargo/config.toml

@@ -1,2 +0,0 @@
-[build]
-target = "x86_64-unknown-linux-musl"

+ 32 - 17
Makefile

@@ -1,41 +1,56 @@
-# The toolchain we use.
-# You can get it by running DragonOS' `tools/bootstrap.sh`
-TOOLCHAIN="+nightly-2023-08-15-x86_64-unknown-linux_dragonos-gnu"
+TOOLCHAIN="+nightly-2023-08-15-x86_64-unknown-linux-gnu"
 RUSTFLAGS+="-C target-feature=+crt-static -C link-arg=-no-pie"
 
+ifdef DADK_CURRENT_BUILD_DIR
 # 如果是在dadk中编译,那么安装到dadk的安装目录中
-INSTALL_DIR?=$(DADK_CURRENT_BUILD_DIR)
+	INSTALL_DIR = $(DADK_CURRENT_BUILD_DIR)
+else
 # 如果是在本地编译,那么安装到当前目录下的install目录中
-INSTALL_DIR?=./install
-
+	INSTALL_DIR = ./install
+endif
+
+ifeq ($(ARCH), x86_64)
+	export RUST_TARGET=x86_64-unknown-linux-musl
+else ifeq ($(ARCH), riscv64)
+	export RUST_TARGET=riscv64gc-unknown-linux-gnu
+else 
+# 默认为x86_86,用于本地编译
+	export RUST_TARGET=x86_64-unknown-linux-musl
+endif
 
 run:
-	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run
+	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run --target $(RUST_TARGET)
 
 build:
-	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build
+	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --target $(RUST_TARGET)
 
 clean:
-	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean
+	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean --target $(RUST_TARGET)
 
 test:
-	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) test
+	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) test --target $(RUST_TARGET)
 
 doc:
-	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) doc
+	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) doc --target $(RUST_TARGET)
+
+fmt:
+	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) fmt
+
+fmt-check:
+	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) fmt --check
 
 run-release:
-	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run --release
+	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run --target $(RUST_TARGET) --release
 
 build-release:
-	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --release
+	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --target $(RUST_TARGET) --release
 
 clean-release:
-	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean --release
+	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean --target $(RUST_TARGET) --release
 
 test-release:
-	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) test --release
+	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) test --target $(RUST_TARGET) --release
 
 .PHONY: install
-install: 
-	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) install --path . --no-track --root $(INSTALL_DIR) --force
+install:
+	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) install --target $(RUST_TARGET) --path . --no-track --root $(INSTALL_DIR) --force