Skip to content

Commit

Permalink
使用musl进行编译 (#33)
Browse files Browse the repository at this point in the history
* 把drstd换成musl
  • Loading branch information
yuyi2439 authored Feb 2, 2024
1 parent 4768985 commit dfd3fd9
Show file tree
Hide file tree
Showing 35 changed files with 139 additions and 377 deletions.
12 changes: 1 addition & 11 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
[build]
target = "./x86_64-unknown-dragonos.json"

[unstable]
build-std = ["core", "compiler_builtins", "alloc"]
build-std-features = ["compiler-builtins-mem"]

[target.'cfg(target_os = "dragonos")']
rustflags = [
"-C", "target-feature=+crt-static",
"-C", "link-arg=-no-pie",
]
target = "x86_64-unknown-linux-musl"
6 changes: 6 additions & 0 deletions .github/workflows/cache-toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ jobs:
rustup target add x86_64-unknown-none
rustup component add rust-src --toolchain nightly-2023-08-15-x86_64-unknown-linux-gnu
rustup component add rustfmt
rustup toolchain install nightly-2023-08-15-x86_64-unknown-linux-gnu
rustup component add rust-src --toolchain nightly-2023-08-15-x86_64-unknown-linux-gnu
rustup target add x86_64-unknown-linux-musl --toolchain nightly-2023-08-15-x86_64-unknown-linux-gnu
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
cargo install dadk --version 0.1.2
2 changes: 1 addition & 1 deletion .github/workflows/standard-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ jobs:

- name: Build check
run: |
make all -j $(nproc)
make build-release -j $(nproc)
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
Cargo.lock
/DragonReach
/install
6 changes: 1 addition & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,5 @@
"./Cargo.toml",
"./systemctl/Cargo.toml"
],
"rust-analyzer.check.overrideCommand": [
"make",
"check"
],
// "rust-analyzer.cargo.target": "x86_64-unknown-dragonos",
"rust-analyzer.checkOnSave": true
}
13 changes: 5 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@ edition = "2021"
name = "DragonReach"
path = "src/main.rs"

[[bin]]
name = "systemctl"
path = "systemctl/src/main.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
hashbrown = "0.11"
cfg-if = { version = "1.0"}

[target.'cfg(target_os = "dragonos")'.dependencies]
drstd = {git = "https://github.com/DragonOS-Community/drstd.git", revision = "8b1e314e01"}
dragonos-dsc = { git = "https://git.mirrors.dragonos.org/DragonOS-Community/dragonos-dsc.git", rev = "aa61cb0109" }

lazy_static = { version = "1.4.0", default-features = false, features = ["spin_no_std"] }

[target.'cfg(not(target_os = "dragonos"))'.dependencies]
lazy_static = { version = "1.4.0" }
libc = "0.2"

[profile.release]
panic = 'abort'
Expand Down
63 changes: 25 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,50 +1,37 @@
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
# The toolchain we use.
# You can get it by running DragonOS' `tools/bootstrap.sh`
TOOLCHAIN="+nightly-2023-08-15-x86_64-unknown-linux-gnu"
RUSTFLAGS+="-C target-feature=+crt-static -C link-arg=-no-pie"

OUTPUT_DIR = $(DADK_BUILD_CACHE_DIR_DRAGONREACH_0_1_0)
REACH_ETC_DIR=$(OUTPUT_DIR)/etc/reach
REACH_BIN_DIR=$(OUTPUT_DIR)/bin/
TMP_INSTALL_DIR=$(OUTPUT_DIR)/tmp_install
# 如果是在dadk中编译,那么安装到dadk的安装目录中
INSTALL_DIR?=$(DADK_CURRENT_BUILD_DIR)
# 如果是在本地编译,那么安装到当前目录下的install目录中
INSTALL_DIR?=./install

all: build

build:
@$(MAKE) -C ./systemctl build
cargo +nightly-2023-08-15 -Z build-std=core,alloc,compiler_builtins build --target ./x86_64-unknown-dragonos.json --release
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build

install:
mkdir -p $(TMP_INSTALL_DIR)
mkdir -p $(REACH_ETC_DIR)
mkdir -p $(REACH_ETC_DIR)/system/
mkdir -p $(REACH_BIN_DIR)
mkdir -p $(REACH_ETC_DIR)/ipc/

cp ./parse_test/shell.service $(REACH_ETC_DIR)/system/shell.service

cargo +nightly-2023-08-15 -Z build-std=core,alloc,compiler_builtins install --target $(TARGET) --path . --root $(TMP_INSTALL_DIR)
mv $(TMP_INSTALL_DIR)/bin/DragonReach $(REACH_BIN_DIR)/DragonReach

cargo -Z build-std=core,alloc,compiler_builtins install --target $(TARGET) --path ./systemctl --root $(TMP_INSTALL_DIR)
mv $(TMP_INSTALL_DIR)/bin/systemctl $(REACH_BIN_DIR)/systemctl

rm -rf $(TMP_INSTALL_DIR)

build-linux:
@$(MAKE) -C ./systemctl build-linux
cargo -Z build-std=core,alloc,compiler_builtins build --target x86_64-unknown-linux-gnu
run-dragonreach:
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run --bin DragonReach

clean:
cargo clean
@$(MAKE) -C ./systemctl clean
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean

build-release:
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --release

clean-release:
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean --release

fmt:
cargo fmt
@$(MAKE) -C ./systemctl fmt
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) fmt

fmt-check:
cargo fmt --check
@$(MAKE) -C ./systemctl fmt-check
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) fmt --check

check:
cargo -Z build-std=core,alloc,compiler_builtins check --workspace --message-format=json --target ./x86_64-unknown-dragonos.json
@$(MAKE) -C ./systemctl check
.PHONY: install
install:
mkdir -p $(INSTALL_DIR)/etc/reach/system
cp ./parse_test/shell.service $(INSTALL_DIR)/etc/reach/system/shell.service
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) install --path . --no-track --root $(INSTALL_DIR) --force
2 changes: 0 additions & 2 deletions src/error/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
pub mod parse_error;
pub mod runtime_error;

use std::string::String;

pub trait ErrorFormat {
fn error_format(&self) -> String;
}
4 changes: 0 additions & 4 deletions src/error/parse_error/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use std::format;
use std::string::String;
use std::string::ToString;

use super::ErrorFormat;
/// 解析错误,错误信息应该包括文件名以及行号
#[repr(i32)]
Expand Down
3 changes: 0 additions & 3 deletions src/error/runtime_error/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::ErrorFormat;

use std::format;
use std::string::String;

#[derive(Debug)]
pub enum RuntimeErrorType {
//启动失败
Expand Down
4 changes: 1 addition & 3 deletions src/executor/dep_graph/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::sync::Arc;
use std::sync::Mutex;
use std::vec::Vec;
use std::sync::{Arc, Mutex};

use crate::manager::UnitManager;
use crate::{
Expand Down
11 changes: 5 additions & 6 deletions src/executor/service_executor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
use std::{
process::{Command, Stdio},
time::Duration,
};

use crate::{
error::runtime_error::{RuntimeError, RuntimeErrorType},
manager::{timer_manager::TimerManager, UnitManager},
Expand All @@ -8,12 +13,6 @@ use crate::{
},
};

use std::process::Command;
use std::process::Stdio;
use std::time::Duration;
use std::vec::Vec;
use std::{eprint, eprintln};

use super::{Executor, ExitStatus};

pub struct ServiceExecutor;
Expand Down
24 changes: 4 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
#![no_std]
#![no_main]
#![feature(slice_pattern)]
#![feature(fn_traits)]

#[cfg(target_os = "dragonos")]
extern crate drstd as std;

extern crate hashbrown;
#![allow(non_snake_case)]

mod contants;
mod error;
Expand All @@ -18,23 +10,16 @@ mod task;
mod time;
mod unit;

use std::{eprint, eprintln};

use std::string::ToString;
use std::vec::Vec;

use error::ErrorFormat;
use executor::Executor;
use manager::timer_manager::TimerManager;
use manager::Manager;
use manager::{timer_manager::TimerManager, Manager};
use parse::UnitParser;
use systemctl::listener::Systemctl;

pub struct FileDescriptor(usize);

const DRAGON_REACH_UNIT_DIR: &'static str = "/etc/reach/system/";

#[no_mangle]
fn main() {
// 初始化
Systemctl::init();
Expand All @@ -46,9 +31,8 @@ fn main() {
if let Ok(entry) = entry {
if let Ok(file_type) = entry.file_type() {
if file_type.is_file() {
let filename = entry.file_name();
let filename = filename.to_str().unwrap();
units_file_name.push(filename.to_string());
let filename = entry.file_name().to_str().unwrap().to_string();
units_file_name.push(filename);
}
}
}
Expand Down
Loading

0 comments on commit dfd3fd9

Please sign in to comment.