Browse Source

修复了未正确定义Target引起的错误 (#36)

* 修复了未正确定义Target引起的错误

* 修复了环境变量的错误定义

* 修改Makefile以适配不同架构

* 解决未设置rustflags导致pagefault的问题

---------

Co-authored-by: longjin <longjin@DragonOS.org>
Chiichen 1 year ago
parent
commit
40362c48d6
3 changed files with 20 additions and 10 deletions
  1. 0 2
      .cargo/config.toml
  2. 1 1
      Cargo.toml
  3. 19 7
      Makefile

+ 0 - 2
.cargo/config.toml

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

+ 1 - 1
Cargo.toml

@@ -15,7 +15,7 @@ path = "systemctl/src/main.rs"
 
 [dependencies]
 hashbrown = "0.11"
-cfg-if = { version = "1.0"}
+cfg-if = { version = "1.0" }
 lazy_static = { version = "1.4.0" }
 libc = "0.2"
 

+ 19 - 7
Makefile

@@ -3,26 +3,38 @@
 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
+
 build:
-	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build
+	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --target $(RUST_TARGET)
 
 run-dragonreach:
-	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run --bin DragonReach
+	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run --target $(RUST_TARGET) --bin DragonReach
 
 clean:
 	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean
 
 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
 
 fmt:
 	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) fmt
@@ -35,4 +47,4 @@ install:
 	mkdir -p $(INSTALL_DIR)/etc/reach/system
 	mkdir -p $(INSTALL_DIR)/etc/reach/ipc
 	cp ./parse_test/shell.service $(INSTALL_DIR)/etc/reach/system/shell.service
-	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) install --path . --no-track --root $(INSTALL_DIR) --force
+	RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) install --target $(RUST_TARGET) --path . --no-track --root $(INSTALL_DIR) --force