mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 09:23:25 +00:00
Gone with x86_64-custom
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
e3c227ae06
commit
7eac2772d0
23
.github/workflows/cargo_check.yml
vendored
23
.github/workflows/cargo_check.yml
vendored
@ -1,23 +0,0 @@
|
||||
name: Cargo check
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
container: asterinas/asterinas:0.3.1
|
||||
steps:
|
||||
- run: echo "Running in asterinas/asterinas:0.3.1"
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- run: make install_osdk
|
||||
|
||||
- name: Check
|
||||
id: check
|
||||
run: make check
|
29
.github/workflows/unit_test.yml
vendored
29
.github/workflows/unit_test.yml
vendored
@ -1,29 +0,0 @@
|
||||
name: Unit test
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
container: asterinas/asterinas:0.3.1
|
||||
steps:
|
||||
- run: echo "Running in asterinas/asterinas:0.3.1"
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- run: make install_osdk
|
||||
|
||||
- name: Usermode Unit test
|
||||
id: usermode_unit_test
|
||||
run: make test
|
||||
|
||||
- name: Ktest Unit Test
|
||||
id: ktest_unit_test
|
||||
run: make update_initramfs && make ktest
|
||||
|
||||
# TODO: add component check.
|
@ -1,5 +1,5 @@
|
||||
[workspace]
|
||||
|
||||
resolver = "2"
|
||||
members = [
|
||||
"framework/aster-frame",
|
||||
"framework/libs/align_ext",
|
||||
@ -28,7 +28,6 @@ members = [
|
||||
"kernel/libs/typeflags",
|
||||
"kernel/libs/typeflags-util",
|
||||
]
|
||||
|
||||
exclude = [
|
||||
"osdk",
|
||||
"target/osdk/base",
|
||||
|
4
Makefile
4
Makefile
@ -125,10 +125,10 @@ docs:
|
||||
@cd docs && mdbook build # Build mdBook
|
||||
|
||||
format:
|
||||
./tools/format_all.sh
|
||||
@./tools/format_all.sh
|
||||
|
||||
check:
|
||||
./tools/format_all.sh --check # Check Rust format issues
|
||||
@./tools/format_all.sh --check # Check Rust format issues
|
||||
@cargo osdk clippy
|
||||
|
||||
clean:
|
||||
|
@ -29,7 +29,7 @@ trapframe = { git = "https://github.com/asterinas/trapframe-rs", rev = "2f37590"
|
||||
unwinding = { version = "0.2.1", default-features = false, features = ["fde-static", "hide-trace", "panic", "personality", "unwinder"] }
|
||||
volatile = { version = "0.4.5", features = ["unstable"] }
|
||||
|
||||
[target.x86_64-custom.dependencies]
|
||||
[target.x86_64-unknown-none.dependencies]
|
||||
x86_64 = "0.14.2"
|
||||
x86 = "0.52.0"
|
||||
acpi = "4.1.1"
|
||||
|
@ -13,17 +13,5 @@ x86_64 = "0.14.2"
|
||||
aster-time = { path = "comps/time" }
|
||||
aster-framebuffer = { path = "comps/framebuffer" }
|
||||
|
||||
[profile.dev]
|
||||
opt-level = 0
|
||||
debug = true
|
||||
lto = false
|
||||
panic = "unwind"
|
||||
|
||||
[profile.release]
|
||||
opt-level = 3
|
||||
debug = false
|
||||
lto = false
|
||||
panic = "unwind"
|
||||
|
||||
[features]
|
||||
intel_tdx = ["aster-frame/intel_tdx", "aster-nix/intel_tdx"]
|
||||
|
@ -28,7 +28,7 @@ pub fn controlled(
|
||||
item: proc_macro::TokenStream,
|
||||
) -> proc_macro::TokenStream {
|
||||
let attr = attr.to_string();
|
||||
if attr.len() != 0 {
|
||||
if !attr.is_empty() {
|
||||
panic!("controlled cannot accept inner tokens.")
|
||||
}
|
||||
let mut tokens: proc_macro::TokenStream = quote!(
|
||||
@ -45,7 +45,7 @@ pub fn uncontrolled(
|
||||
item: proc_macro::TokenStream,
|
||||
) -> proc_macro::TokenStream {
|
||||
let attr = attr.to_string();
|
||||
if attr.len() != 0 {
|
||||
if !attr.is_empty() {
|
||||
panic!("uncontrolled cannot accept inner tokens.")
|
||||
}
|
||||
let mut tokens: proc_macro::TokenStream = quote!(
|
||||
|
2
osdk/Cargo.lock
generated
2
osdk/Cargo.lock
generated
@ -128,7 +128,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cargo-osdk"
|
||||
version = "0.2.0"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"assert_cmd",
|
||||
"clap",
|
||||
|
@ -4,13 +4,20 @@
|
||||
//! It will depend on the kernel crate.
|
||||
//!
|
||||
|
||||
use std::{fs, path::Path, str::FromStr};
|
||||
use std::{fs, path::{Path, PathBuf}, str::FromStr};
|
||||
|
||||
use crate::util::get_cargo_metadata;
|
||||
|
||||
pub fn new_base_crate(
|
||||
base_crate_path: impl AsRef<Path>,
|
||||
dep_crate_name: &str,
|
||||
dep_crate_path: impl AsRef<Path>,
|
||||
) {
|
||||
let workspace_root = {
|
||||
let meta = get_cargo_metadata(None::<&str>, None::<&[&str]>).unwrap();
|
||||
PathBuf::from(meta.get("workspace_root").unwrap().as_str().unwrap())
|
||||
};
|
||||
|
||||
if base_crate_path.as_ref().exists() {
|
||||
std::fs::remove_dir_all(&base_crate_path).unwrap();
|
||||
}
|
||||
@ -47,12 +54,8 @@ pub fn new_base_crate(
|
||||
std::env::set_current_dir(&base_crate_path).unwrap();
|
||||
|
||||
// Add linker.ld file
|
||||
let linker_ld = include_str!("x86_64-custom.ld.template");
|
||||
fs::write("x86_64-custom.ld", linker_ld).unwrap();
|
||||
|
||||
// Add target json file
|
||||
let target_json = include_str!("x86_64-custom.json.template");
|
||||
fs::write("x86_64-custom.json", target_json).unwrap();
|
||||
let linker_ld = include_str!("x86_64.ld.template");
|
||||
fs::write("x86_64.ld", linker_ld).unwrap();
|
||||
|
||||
// Overrite the main.rs file
|
||||
let main_rs = include_str!("main.rs.template");
|
||||
@ -64,7 +67,7 @@ pub fn new_base_crate(
|
||||
add_manifest_dependency(dep_crate_name, dep_crate_path);
|
||||
|
||||
// Copy the manifest configurations from the target crate to the base crate
|
||||
copy_manifest_configurations(base_crate_path);
|
||||
copy_profile_configurations(workspace_root);
|
||||
|
||||
// Get back to the original directory
|
||||
std::env::set_current_dir(original_dir).unwrap();
|
||||
@ -100,8 +103,8 @@ fn add_manifest_dependency(crate_name: &str, crate_path: impl AsRef<Path>) {
|
||||
fs::write(mainfest_path, content).unwrap();
|
||||
}
|
||||
|
||||
fn copy_manifest_configurations(target_crate_path: impl AsRef<Path>) {
|
||||
let target_manifest_path = target_crate_path.as_ref().join("Cargo.toml");
|
||||
fn copy_profile_configurations(workspace_root: impl AsRef<Path>) {
|
||||
let target_manifest_path = workspace_root.as_ref().join("Cargo.toml");
|
||||
let manifest_path = "Cargo.toml";
|
||||
|
||||
let target_manifest: toml::Table = {
|
||||
|
@ -1,21 +0,0 @@
|
||||
{
|
||||
"llvm-target": "x86_64-unknown-none",
|
||||
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
|
||||
"code-model": "kernel",
|
||||
"cpu": "x86-64",
|
||||
"arch": "x86_64",
|
||||
"target-endian": "little",
|
||||
"target-pointer-width": "64",
|
||||
"target-c-int-width": "32",
|
||||
"os": "none",
|
||||
"executables": true,
|
||||
"linker-flavor": "ld.lld",
|
||||
"linker": "rust-lld",
|
||||
"pre-link-args": {
|
||||
"ld.lld": [
|
||||
"--script=x86_64-custom.ld"
|
||||
]
|
||||
},
|
||||
"disable-redzone": true,
|
||||
"features": "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float"
|
||||
}
|
@ -3,11 +3,7 @@
|
||||
mod bin;
|
||||
mod grub;
|
||||
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
process,
|
||||
str::FromStr,
|
||||
};
|
||||
use std::{path::Path, process};
|
||||
|
||||
use bin::strip_elf_for_qemu;
|
||||
|
||||
@ -40,6 +36,7 @@ pub fn execute_build_command(config: &BuildConfig) {
|
||||
&osdk_target_directory,
|
||||
&ws_target_directory,
|
||||
config,
|
||||
&[],
|
||||
);
|
||||
}
|
||||
|
||||
@ -48,6 +45,7 @@ pub fn create_base_and_build(
|
||||
osdk_target_directory: impl AsRef<Path>,
|
||||
cargo_target_directory: impl AsRef<Path>,
|
||||
config: &BuildConfig,
|
||||
rustflags: &[&str],
|
||||
) -> Bundle {
|
||||
let base_crate_path = osdk_target_directory.as_ref().join("base");
|
||||
new_base_crate(
|
||||
@ -62,6 +60,7 @@ pub fn create_base_and_build(
|
||||
&osdk_target_directory,
|
||||
&cargo_target_directory,
|
||||
config,
|
||||
rustflags,
|
||||
);
|
||||
std::env::set_current_dir(original_dir).unwrap();
|
||||
bundle
|
||||
@ -72,6 +71,7 @@ pub fn do_build(
|
||||
osdk_target_directory: impl AsRef<Path>,
|
||||
cargo_target_directory: impl AsRef<Path>,
|
||||
config: &BuildConfig,
|
||||
rustflags: &[&str],
|
||||
) -> Bundle {
|
||||
if bundle_path.as_ref().exists() {
|
||||
std::fs::remove_dir_all(&bundle_path).unwrap();
|
||||
@ -93,7 +93,7 @@ pub fn do_build(
|
||||
};
|
||||
|
||||
info!("Building kernel ELF");
|
||||
let aster_elf = build_kernel_elf(&config.cargo_args, &cargo_target_directory);
|
||||
let aster_elf = build_kernel_elf(&config.cargo_args, &cargo_target_directory, rustflags);
|
||||
|
||||
if matches!(config.manifest.qemu.machine, QemuMachine::Microvm) {
|
||||
let stripped_elf = strip_elf_for_qemu(&osdk_target_directory, &aster_elf);
|
||||
@ -117,13 +117,25 @@ pub fn do_build(
|
||||
bundle
|
||||
}
|
||||
|
||||
fn build_kernel_elf(args: &CargoArgs, cargo_target_directory: impl AsRef<Path>) -> AsterBin {
|
||||
let target_json_path = PathBuf::from_str("x86_64-custom.json").unwrap();
|
||||
fn build_kernel_elf(args: &CargoArgs, cargo_target_directory: impl AsRef<Path>, rustflags: &[&str]) -> AsterBin {
|
||||
let target = "x86_64-unknown-none";
|
||||
|
||||
let env_rustflags = std::env::var("RUSTFLAGS").unwrap_or_default();
|
||||
let mut rustflags = Vec::from(rustflags);
|
||||
// We disable RELRO and PIC here because they cause link failures
|
||||
rustflags.extend(vec![
|
||||
&env_rustflags,
|
||||
"-C link-arg=-Tx86_64.ld",
|
||||
"-C code-model=kernel",
|
||||
"-C relocation-model=static",
|
||||
"-Z relro-level=off",
|
||||
]);
|
||||
|
||||
let mut command = cargo();
|
||||
command.env_remove("RUSTUP_TOOLCHAIN");
|
||||
command.env("RUSTFLAGS", rustflags.join(" "));
|
||||
command.arg("build");
|
||||
command.arg("--target").arg(&target_json_path);
|
||||
command.arg("--target").arg(target);
|
||||
command
|
||||
.arg("--target-dir")
|
||||
.arg(cargo_target_directory.as_ref());
|
||||
@ -135,9 +147,7 @@ fn build_kernel_elf(args: &CargoArgs, cargo_target_directory: impl AsRef<Path>)
|
||||
process::exit(Errno::ExecuteCommand as _);
|
||||
}
|
||||
|
||||
let aster_bin_path = cargo_target_directory
|
||||
.as_ref()
|
||||
.join(target_json_path.file_stem().unwrap().to_str().unwrap());
|
||||
let aster_bin_path = cargo_target_directory.as_ref().join(target);
|
||||
let aster_bin_path = if args.profile == "dev" {
|
||||
aster_bin_path.join("debug")
|
||||
} else {
|
||||
|
@ -3,13 +3,14 @@
|
||||
use std::process;
|
||||
|
||||
use super::util::{cargo, COMMON_CARGO_ARGS};
|
||||
use crate::{commands::util::create_target_json, error::Errno, error_msg};
|
||||
use crate::{error::Errno, error_msg};
|
||||
|
||||
pub fn execute_check_command() {
|
||||
let target_json_path = create_target_json();
|
||||
|
||||
let mut command = cargo();
|
||||
command.arg("check").arg("--target").arg(target_json_path);
|
||||
command
|
||||
.arg("check")
|
||||
.arg("--target")
|
||||
.arg("x86_64-unkown-none");
|
||||
command.args(COMMON_CARGO_ARGS);
|
||||
let status = command.status().unwrap();
|
||||
if !status.success() {
|
||||
|
@ -3,13 +3,16 @@
|
||||
use std::process;
|
||||
|
||||
use super::util::{cargo, COMMON_CARGO_ARGS};
|
||||
use crate::{commands::util::create_target_json, error::Errno, error_msg};
|
||||
use crate::{error::Errno, error_msg};
|
||||
|
||||
pub fn execute_clippy_command() {
|
||||
let target_json_path = create_target_json();
|
||||
|
||||
let mut command = cargo();
|
||||
command.arg("clippy").arg("-h");
|
||||
command
|
||||
.arg("clippy")
|
||||
.arg("-h")
|
||||
.arg("--target")
|
||||
.arg("x86_64-unknown-none")
|
||||
.args(COMMON_CARGO_ARGS);
|
||||
info!("Running `cargo clippy -h`");
|
||||
let output = command.output().unwrap();
|
||||
if !output.status.success() {
|
||||
@ -20,8 +23,11 @@ pub fn execute_clippy_command() {
|
||||
}
|
||||
|
||||
let mut command = cargo();
|
||||
command.arg("clippy").arg("--target").arg(target_json_path);
|
||||
command.args(COMMON_CARGO_ARGS);
|
||||
command
|
||||
.arg("clippy")
|
||||
.arg("--target")
|
||||
.arg("x86_64-unknown-none")
|
||||
.args(COMMON_CARGO_ARGS);
|
||||
// TODO: Add support for custom clippy args using OSDK commandline rather than hardcode it.
|
||||
command.args(["--", "-D", "warnings"]);
|
||||
let status = command.status().unwrap();
|
||||
|
@ -50,6 +50,7 @@ pub fn execute_run_command(config: &RunConfig) {
|
||||
&osdk_target_directory,
|
||||
&ws_target_directory,
|
||||
&required_build_config,
|
||||
&[],
|
||||
);
|
||||
|
||||
bundle.run(config);
|
||||
|
@ -52,13 +52,12 @@ pub static KTEST_CRATE_WHITELIST: Option<&[&str]> = Some(&{:#?});
|
||||
};
|
||||
let original_dir = std::env::current_dir().unwrap();
|
||||
std::env::set_current_dir(&target_crate_dir).unwrap();
|
||||
// Add `--cfg ktest` to RUSTFLAGS
|
||||
std::env::set_var("RUSTFLAGS", "--cfg ktest");
|
||||
let bundle = do_build(
|
||||
default_bundle_directory,
|
||||
&osdk_target_directory,
|
||||
&ws_target_directory,
|
||||
&required_build_config,
|
||||
&["--cfg ktest", "-C panic=unwind"],
|
||||
);
|
||||
std::env::remove_var("RUSTFLAGS");
|
||||
std::env::set_current_dir(original_dir).unwrap();
|
||||
|
@ -1,8 +1,6 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use std::{fs, path::PathBuf, process::Command};
|
||||
|
||||
use crate::util::get_target_directory;
|
||||
use std::process::Command;
|
||||
|
||||
pub const COMMON_CARGO_ARGS: &[&str] = &[
|
||||
"-Zbuild-std=core,alloc,compiler_builtins",
|
||||
@ -14,18 +12,3 @@ pub const DEFAULT_TARGET_RELPATH: &str = "osdk";
|
||||
pub fn cargo() -> Command {
|
||||
Command::new("cargo")
|
||||
}
|
||||
|
||||
pub fn create_target_json() -> PathBuf {
|
||||
let target_osdk_dir = get_target_directory().join(DEFAULT_TARGET_RELPATH);
|
||||
fs::create_dir_all(&target_osdk_dir).unwrap();
|
||||
|
||||
let target_json_path = target_osdk_dir.join("x86_64-custom.json");
|
||||
if target_json_path.is_file() {
|
||||
return target_json_path;
|
||||
}
|
||||
|
||||
let contents = include_str!("../base_crate/x86_64-custom.json.template");
|
||||
fs::write(&target_json_path, contents).unwrap();
|
||||
|
||||
target_json_path
|
||||
}
|
||||
|
@ -221,6 +221,7 @@ FROM rust
|
||||
RUN apt update && apt-get install -y --no-install-recommends \
|
||||
cpio \
|
||||
cpuid \
|
||||
exfatprogs \
|
||||
file \
|
||||
gdb \
|
||||
grub-efi-amd64 \
|
||||
@ -237,8 +238,7 @@ RUN apt update && apt-get install -y --no-install-recommends \
|
||||
unzip \
|
||||
vim \
|
||||
xorriso \
|
||||
zip \
|
||||
exfatprogs
|
||||
zip
|
||||
# Clean apt cache
|
||||
RUN apt clean && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
|
Reference in New Issue
Block a user