1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-23 00:16:17 +04:00
rCore/modules/hello_rust/build.sh
gjz010 7b8252eb1b Basic loadable kernel module support, with a module template written in Rust.
Under aarch64 and x86_64, hello_rust can be built and loaded by `/busybox insmod hello_rust.ko`.
2019-06-07 20:59:51 +08:00

32 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
ARCH=x86_64
TEXT_TYPE=elf64-x86-64
BIN_ARCH=i386:x86-64
PREFIX=
echo "Step 1. Fetching dependencies according to cargo."
echo "// Dummy file" > src/lib.rs
echo '#![no_std]' >> src/lib.rs
echo "extern crate rcore;" >> src/lib.rs
cargo xbuild --target=../../kernel/targets/$ARCH.json -vv --release
echo "Step 2. Compile the library"
echo '#![no_std]' > src/lib.rs
echo '#![feature(alloc)]' >> src/lib.rs
echo "extern crate rcore;" >> src/lib.rs
echo "mod main;" >> src/lib.rs
rustc --edition=2018 --crate-name hello_rust src/lib.rs \
--color always --crate-type cdylib -C debuginfo=2 \
--out-dir ./target/$ARCH/release/objs \
--target ../../kernel/targets/$ARCH.json \
-L dependency=target/$ARCH/release/deps \
-L dependency=target/release/deps \
--emit=obj --sysroot target/sysroot \
-L all=../../kernel/target/$ARCH/release/deps
echo "Step 3. Packing the library into kernel module."
"$PREFIX"objcopy --input binary --output $TEXT_TYPE \
--binary-architecture $BIN_ARCH\
--rename-section .data=.rcore-lkm,CONTENTS,READONLY\
lkm_info.txt target/$ARCH/release/objs/lkm_info.o
"$PREFIX"strip target/$ARCH/release/objs/lkm_info.o
"$PREFIX"gcc -shared -o target/$ARCH/release/hello_rust.ko -nostdlib target/$ARCH/release/objs/*.o
#cargo xbuild --target=../../kernel/targets/x86_64.json -vv