Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove alphine #325

Merged
merged 9 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 19 additions & 36 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
profile: minimal
toolchain: ${{ env.rust_toolchain }}
components: rust-src, llvm-tools-preview, rustfmt, clippy
components: rust-src, llvm-tools-preview

- name: Run unit test
uses: actions-rs/cargo@v1
Expand Down Expand Up @@ -49,23 +49,6 @@ jobs:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# path-to-lcov: ${{ steps.coverage.outputs.report }}

bench-test:
name: Bench Test
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.rust_toolchain }}
components: rust-src, llvm-tools-preview, rustfmt, clippy

- name: Run bench test
uses: actions-rs/cargo@v1
with:
command: bench

zircon-core-test-libos:
name: Zircon Core Test Libos
runs-on: ubuntu-20.04
Expand All @@ -78,7 +61,7 @@ jobs:
with:
profile: minimal
toolchain: ${{ env.rust_toolchain }}
components: rust-src, llvm-tools-preview, rustfmt, clippy
components: rust-src, llvm-tools-preview

- name: Pull prebuilt images
run: |
Expand Down Expand Up @@ -110,7 +93,7 @@ jobs:
with:
profile: minimal
toolchain: ${{ env.rust_toolchain }}
components: rust-src, llvm-tools-preview, rustfmt, clippy
components: rust-src, llvm-tools-preview

- name: Pull prebuilt images
run: |
Expand Down Expand Up @@ -160,7 +143,7 @@ jobs:
with:
profile: minimal
toolchain: ${{ env.rust_toolchain }}
components: rust-src, llvm-tools-preview, rustfmt, clippy
components: rust-src, llvm-tools-preview

- name: Cache musl toolchain
uses: actions/cache@v3
Expand All @@ -169,7 +152,7 @@ jobs:
key: ${{ matrix.arch }}-linux-musl-cross

- name: Prepare rootfs
run: make libc-test
run: cargo xtask libos-libc-test

- name: Install python dependencies
run: pip3 install -r tests/requirements.txt
Expand Down Expand Up @@ -198,13 +181,7 @@ jobs:
with:
profile: minimal
toolchain: ${{ env.rust_toolchain }}
components: rust-src, llvm-tools-preview, rustfmt, clippy

- if: matrix.arch == 'riscv64'
uses: actions-rs/[email protected]
with:
crate: cargo-binutils
version: latest
components: rust-src, llvm-tools-preview

- name: Cache QEMU
id: cache-qemu
Expand Down Expand Up @@ -234,6 +211,12 @@ jobs:
- name: Prepare rootfs
run: make libc-test ARCH=${{ matrix.arch }} && make image ARCH=${{ matrix.arch }}

- if: matrix.arch == 'riscv64'
uses: actions-rs/[email protected]
with:
crate: cargo-binutils
version: latest

- name: Install python dependencies
run: pip3 install -r tests/requirements.txt

Expand Down Expand Up @@ -261,13 +244,7 @@ jobs:
with:
profile: minimal
toolchain: ${{ env.rust_toolchain }}
components: rust-src, llvm-tools-preview, rustfmt, clippy

- if: matrix.arch == 'riscv64'
uses: actions-rs/[email protected]
with:
crate: cargo-binutils
version: latest
components: rust-src, llvm-tools-preview

- name: Cache QEMU
id: cache-qemu
Expand Down Expand Up @@ -297,6 +274,12 @@ jobs:
- name: Prepare rootfs
run: make other-test ARCH=${{ matrix.arch }} && make image ARCH=${{ matrix.arch }}

- if: matrix.arch == 'riscv64'
uses: actions-rs/[email protected]
with:
crate: cargo-binutils
version: latest

- name: Install python dependencies
run: pip3 install -r tests/requirements.txt

Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ clean:
rm -rf zCore/disk
find zCore -maxdepth 1 -name "*.img" -delete

rt-test:
cd rootfs/x86_64 && git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/clrkwllms/rt-tests --depth 1
cd rootfs/x86_64/rt-tests && make
echo x86 gcc build rt-test,now need manual modificy.
# rt-test:
# cd rootfs/x86_64 && git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/clrkwllms/rt-tests --depth 1
# cd rootfs/x86_64/rt-tests && make
# echo x86 gcc build rt-test,now need manual modificy.
2 changes: 1 addition & 1 deletion loader/examples/linux-libos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async fn main() {
}

let envs = vec!["PATH=/usr/sbin:/usr/bin:/sbin:/bin".into()];
let rootfs_path = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("../rootfs/x86_64");
let rootfs_path = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("../rootfs/libos");
let hostfs = rcore_fs_hostfs::HostFS::new(rootfs_path);

let proc = zcore_loader::linux::run(args[1..].to_vec(), envs, hostfs);
Expand Down
2 changes: 1 addition & 1 deletion loader/tests/linux.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rcore_fs_hostfs::HostFS;
use std::fs;

const LIBOS_ROOTFS: &str = "../rootfs/x86_64";
const LIBOS_ROOTFS: &str = "../rootfs/libos";

/// test with cmd line
async fn test(cmdline: &str) -> i64 {
Expand Down
2 changes: 1 addition & 1 deletion tests
9 changes: 5 additions & 4 deletions xtask/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
command::{dir, download::wget, CommandExt, Tar},
LinuxRootfs, XError, ORIGIN, TARGET,
LinuxRootfs, XError, ARCHS, TARGET,
};
use std::{path::PathBuf, str::FromStr};

Expand All @@ -28,16 +28,16 @@ impl Arch {
/// Returns the path to store arch-dependent files from network.
#[inline]
pub fn origin(&self) -> PathBuf {
PathBuf::from(ORIGIN).join(self.name())
ARCHS.join(self.name())
}

/// Returns the path to cache arch-dependent generated files durning processes.
#[inline]
pub fn target(&self) -> PathBuf {
PathBuf::from(TARGET).join(self.name())
TARGET.join(self.name())
}

/// 下载 musl 工具链,返回工具链路径。
/// Downloads linux musl toolchain, and returns its path.
pub fn linux_musl_cross(&self) -> PathBuf {
let name = format!("{}-linux-musl-cross", self.name().to_lowercase());

Expand All @@ -47,6 +47,7 @@ impl Arch {
let tgz = origin.join(format!("{name}.tgz"));
let dir = target.join(&name);

dir::create_parent(&dir).unwrap();
dir::rm(&dir).unwrap();
wget(format!("https://musl.cc/{name}.tgz"), &tgz);
Tar::xf(&tgz, Some(target)).invoke();
Expand Down
35 changes: 24 additions & 11 deletions xtask/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
command::{Cargo, CommandExt, Ext, Qemu},
Arch, ArchArg,
command::{BinUtil, Cargo, CommandExt, Ext, Qemu},
Arch, ArchArg, PROJECT_DIR,
};
use std::{fs, path::PathBuf};

Expand Down Expand Up @@ -42,6 +42,10 @@ pub(crate) struct GdbArgs {
port: u16,
}

lazy_static::lazy_static! {
static ref INNER: PathBuf = PROJECT_DIR.join("zCore");
}

impl BuildArgs {
#[inline]
fn arch(&self) -> Arch {
Expand All @@ -50,7 +54,8 @@ impl BuildArgs {

fn dir(&self) -> String {
format!(
"target/{arch}/{mode}",
"{target}/{arch}/{mode}",
target = PROJECT_DIR.join("target").display(),
arch = self.arch().name(),
mode = if self.debug { "debug" } else { "release" }
)
Expand All @@ -61,7 +66,7 @@ impl BuildArgs {
cargo
.package("zcore")
.features(false, &["linux", "board-qemu"])
.target(format!("zCore/{arch}.json", arch = self.arch().name()))
.target(INNER.join(format!("{}.json", self.arch().name())))
.args(&["-Z", "build-std=core,alloc"])
.args(&["-Z", "build-std-features=compiler-builtins-mem"]);
if !self.debug {
Expand All @@ -76,7 +81,7 @@ impl AsmArgs {
pub fn asm(&self) {
// 递归 build
self.build.build();
let out = Ext::new("rust-objdump")
let out = BinUtil::objdump()
.arg(format!("{dir}/zcore", dir = self.build.dir()))
.arg("-d")
.output()
Expand All @@ -99,7 +104,7 @@ impl QemuArgs {
let obj = format!("{dir}/zcore");
let bin = format!("{dir}/zcore.bin");
// 裁剪内核二进制文件
Ext::new("rust-objcopy")
BinUtil::objcopy()
.arg(format!("--binary-architecture={arch_str}"))
.arg(obj.clone())
.arg("--strip-all")
Expand All @@ -109,7 +114,8 @@ impl QemuArgs {
let mut qemu = Qemu::system(arch);
qemu.args(&["-m", "512M"])
.args(&["-kernel", &bin])
.args(&["-initrd", &format!("zCore/{arch_str}.img")])
.arg("-initrd")
.arg(INNER.join(format!("{arch_str}.img")))
.args(&["-append", "\"LOG=warn\""])
.args(&["-display", "none"])
.arg("-no-reboot")
Expand All @@ -126,13 +132,20 @@ impl QemuArgs {
}
Arch::X86_64 => todo!(),
Arch::Aarch64 => {
fs::copy(obj, "zCore/disk/os").unwrap();
fs::copy(obj, INNER.join("disk").join("os")).unwrap();
qemu.args(&["-machine", "virt"])
.args(&["-cpu", "cortex-a72"])
.args(&["-m", "1G"])
.args(&["-bios", "ignored/target/aarch64/firmware/QEMU_EFI.fd"])
.args(&["-hda", "fat:rw:zCore/disk"])
.args(&["-drive", "file=zCore/aarch64.img,if=none,format=raw,id=x0"])
.arg("-bios")
.arg(arch.target().join("firmware").join("QEMU_EFI.fd"))
.args(&["-hda", &format!("fat:rw:{}/disk", INNER.display())])
.args(&[
"-drive",
&format!(
"file={}/aarch64.img,if=none,format=raw,id=x0",
INNER.display()
),
])
.args(&[
"-device",
"virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0",
Expand Down
26 changes: 26 additions & 0 deletions xtask/src/command/binutils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use super::{ext, Cargo, CommandExt};
use std::{ffi::OsStr, process::Command};

ext!(def; BinUtil);

impl BinUtil {
fn new(which: impl AsRef<OsStr>) -> Self {
let which = which.as_ref();
let check = std::str::from_utf8(&Cargo::install().arg("--list").output().stdout)
.unwrap()
.lines()
.any(|line| OsStr::new(line) == which);
if !check {
Cargo::install().arg("cargo-binutils").invoke();
}
Self(Command::new(which))
}

pub fn objcopy() -> Self {
Self::new("rust-objcopy")
}

pub fn objdump() -> Self {
Self::new("rust-objdump")
}
}
11 changes: 7 additions & 4 deletions xtask/src/command/cargo.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use super::{ext, CommandExt};
use std::{ffi::OsStr, process::Command};

pub(crate) struct Cargo(Command);

ext!(Cargo);
ext!(def; Cargo);

impl Cargo {
#[inline]
fn new(sub: &(impl AsRef<OsStr> + ?Sized)) -> Self {
fn new(sub: impl AsRef<OsStr>) -> Self {
let mut git = Self(Command::new("cargo"));
git.arg(sub);
git
Expand Down Expand Up @@ -43,6 +41,11 @@ impl Cargo {
Self::new("run")
}

#[inline]
pub fn install() -> Self {
Self::new("install")
}

#[inline]
pub fn all_features(&mut self) -> &mut Self {
self.arg("--all-features");
Expand Down
4 changes: 1 addition & 3 deletions xtask/src/command/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
use super::{ext, CommandExt};
use std::{ffi::OsStr, path::PathBuf, process::Command};

pub(crate) struct Git(Command);

ext!(Git);
ext!(def; Git);

impl Git {
fn new(sub: impl AsRef<OsStr>) -> Self {
Expand Down
4 changes: 1 addition & 3 deletions xtask/src/command/make.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use super::{ext, CommandExt};
use std::process::Command;

pub(crate) struct Make(Command);

ext!(Make);
ext!(def; Make);

impl Make {
pub fn new() -> Self {
Expand Down
Loading