新增rust ffi (#77)

* 引入cargo

* 取消对Cargo.lock的跟踪

* 解决vscode报错问题

* new: rust的代码能够调用c语言的printk_color

* 1、将原本run.sh的工作拆解,变为几个不同的make命令
2、在docker镜像中编译rust

* 更改workflow

* update workflow

* new: 解决workflow无法通过编译的问题
This commit is contained in:
login
2022-11-11 15:35:37 +08:00
committed by GitHub
parent 5e023cf791
commit 2813126e31
271 changed files with 609 additions and 307 deletions

179
tools/bootstrap.sh Normal file
View File

@ -0,0 +1,179 @@
emulator="qemu"
defpackman="apt-get"
banner()
{
echo "|------------------------------------------|"
echo "| Welcome to the DragonOS bootstrap |"
echo "|------------------------------------------|"
}
congratulations()
{
echo "|-----------Congratulations!---------------|"
echo "| |"
echo "| 你成功安装了DragonOS所需的依赖项! |"
echo "| 您可以通过以下命令运行它: |"
echo "| |"
echo "| make run-docker -j 你的cpu核心数 |"
echo "| |"
echo "|------------------------------------------|"
}
####################################
# 当检测到ubuntu或Debian时执行此函数 #
# 参数:第一个参数为包管理器 #
####################################
install_ubuntu_debian_pkg()
{
echo "检测到 Ubuntu/Debian"
echo "正在更新包管理器的列表..."
sudo "$1" update
echo "正在安装所需的包..."
sudo "$1" install -y \
ca-certificates \
curl \
gnupg \
lsb-release \
llvm-dev libclang-dev clang gcc-multilib \
gcc build-essential fdisk
if [ -z "$(which docker)" ]; then
echo "正在安装docker..."
exit 1
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo $1 update
sudo "$1" install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
else
echo "您的计算机上已经安装了docker"
fi
if [ -z "$(which qemu-system-x86_64)" ]; then
echo "正在安装QEMU虚拟机..."
sudo $1 install -y qemu qemu-system qemu-kvm
else
echo "QEMU已经在您的电脑上安装"
fi
}
install_osx_pkg()
{
echo "Detected OSX! 暂不支持Mac OSX的一键安装"
exit 1
}
####################################################################################
# This function takes care of everything associated to rust, and the version manager
# That controls it, it can install rustup and uninstall multirust as well as making
# sure that the correct version of rustc is selected by rustup
####################################################################################
rustInstall() {
# Check to see if multirust is installed, we don't want it messing with rustup
# In the future we can probably remove this but I believe it's good to have for now
if [ -e /usr/local/lib/rustlib/uninstall.sh ] ; then
echo "您的系统上似乎安装了multirust。"
echo "该工具已被维护人员弃用,并将导致问题。"
echo "如果您愿意此脚本可以从系统中删除multirust"
printf "卸载 multirust (y/N):"
read multirust
if echo "$multirust" | grep -iq "^y" ;then
sudo /usr/local/lib/rustlib/uninstall.sh
else
echo "请手动卸载multistrust和任何其他版本的rust然后重新运行bootstrap.sh"
exit
fi
fi
# If rustup is not installed we should offer to install it for them
if [ -z "$(which rustup)" ]; then
echo "您没有安装rustup,"
echo "我们强烈建议使用rustup, 是否要立即安装?"
echo "*WARNING* 这将会发起这样的一个命令 'curl | sh' "
printf "(y/N): "
read rustup
if echo "$rustup" | grep -iq "^y" ;then
#install rustup
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly
# You have to add the rustup variables to the $PATH
echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" >> ~/.bashrc
# source the variables so that we can execute rustup commands in the current shell
source ~/.cargo/env
source "$HOME/.cargo/env"
else
echo "Rustup will not be installed!"
fi
fi
#
if [ -z "$(which rustc)" ]; then
echo "Rust 还未被安装"
echo "请再次运行脚本接受rustup安装"
echo "或通过以下方式手动安装rustc不推荐"
echo "curl -sSf https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly"
exit
else
echo "是否为Rust换源为Gitee镜像源"
echo "如果您在国内,我们推荐您这样做,以提升网络速度。"
echo "*WARNING* 这将会替换原有的镜像源设置。"
printf "(y/N): "
read change_src
if echo "$change_src" | grep -iq "^y" ;then
touch ~/.cargo/config
bash change_rust_src.sh
else
echo "取消换源,您原有的配置不会被改变。"
fi
echo "正在安装DragonOS所需的rust组件...首次安装需要一些时间来更新索引,请耐心等待..."
cargo install cargo-binutils
rustup toolchain install nightly
rustup default nightly
rustup component add rust-src
rustup component add llvm-tools-preview
rustup target add x86_64-unknown-none
echo "Rust已经成功的在您的计算机上安装请运行 source ~/.cargo/env 以使rust在当前窗口生效"
fi
}
############ 开始执行 ###############
banner
rustInstall
exit
if [ "Darwin" == "$(uname -s)" ]; then
install_osx_pkg "$emulator" || exit 1
else
# Here we will use package managers to determine which operating system the user is using.
# Suse and derivatives
if hash 2>/dev/null zypper; then
suse "$emulator" || exit 1
# Debian or any derivative of it
elif hash 2>/dev/null apt-get; then
install_ubuntu_debian_pkg "$defpackman" || exit 1
# Fedora
elif hash 2>/dev/null dnf; then
fedora "$emulator" || exit 1
# Gentoo
elif hash 2>/dev/null emerge; then
gentoo "$emulator" || exit 1
# SolusOS
elif hash 2>/dev/null eopkg; then
solus "$emulator" || exit 1
# Arch linux
elif hash 2>/dev/null pacman; then
archLinux "$emulator" || exit 1
# FreeBSD
elif hash 2>/dev/null pkg; then
freebsd "$emulator" || exit 1
# Unsupported platform
else
printf "\e[31;1mFatal error: \e[0;31mUnsupported platform, please open an issue\[0m" || exit 1
fi
fi
# 创建磁盘镜像
sudo bash create_hdd_image.sh
congratulations