Skip to content

Instantly share code, notes, and snippets.

@pierzchalski
Created February 16, 2015 02:04
Show Gist options
  • Save pierzchalski/232d4531e4bf76d93b05 to your computer and use it in GitHub Desktop.
Save pierzchalski/232d4531e4bf76d93b05 to your computer and use it in GitHub Desktop.
The diff between a fresh CS3231-asst0 svn load and a working rust build system (if the binaries `rustc' and `llc' are in PATH).
diff --git a/asst0-src/kern/conf/conf.kern b/asst0-src/kern/conf/conf.kern
index d23e6bc..b18ae7f 100644
--- a/asst0-src/kern/conf/conf.kern
+++ b/asst0-src/kern/conf/conf.kern
@@ -425,3 +425,12 @@ file test/synchtest.c
file test/malloctest.c
file test/fstest.c
optfile net test/nettest.c
+
+#######################################
+# #
+# Rust #
+# #
+#######################################
+
+file rust/magic.rs
+
diff --git a/asst0-src/kern/conf/config b/asst0-src/kern/conf/config
index 0d4cef8..281feed 100755
--- a/asst0-src/kern/conf/config
+++ b/asst0-src/kern/conf/config
@@ -670,6 +670,7 @@ awk < $CONFTMP.files '
#/\.y$/ { next; } # will require some makefile hacking to make work
/\.S$/ { next; }
/\.o$/ { next; }
+ /\.rs$/ { next; }
{
printf "\n%s: Unrecognized source file type\n", $1;
exit(1);
@@ -718,7 +719,10 @@ sort < $CONFTMP.files | awk '
else if (machine != "*") {
printf "SRCS.MACHINE.%s+=%s\n", machine, path;
}
- else {
+ else if (ext == "rs") {
+ printf "RUSTSRCS+=%s\n", path;
+ }
+ else {
printf "SRCS+=%s\n", path;
}
}
diff --git a/asst0-src/mk/os161.kernel.mk b/asst0-src/mk/os161.kernel.mk
index e3eddcd..ac94ff6 100644
--- a/asst0-src/mk/os161.kernel.mk
+++ b/asst0-src/mk/os161.kernel.mk
@@ -146,7 +146,7 @@ includelinks:
# blow away the whole compile directory.)
#
clean:
- rm -f *.o *.a tags $(KERNEL)
+ rm -f *.o *.a *.ll tags $(KERNEL)
rm -r includelinks
distclean cleandir: clean
@@ -196,6 +196,23 @@ $(_S_:T:R).o: $(_S_)
$(CC) $(KCFLAGS) -c $(_S_)
.endfor
+.for _S_ in $(RUSTSRCS)
+OBJS+=$(_S_:T:R).o
+$(_S_:T:R).o: $(_S_)
+ rustc --emit=llvm-ir \
+ --crate-type=lib \
+ -C debuginfo=2 \
+ -o $(_S_:R).ll \
+ $(_S_)
+ llc -march=mips \
+ -mcpu=mips1 \
+ -o $(_S_:T:R).o \
+ -filetype=obj \
+ -code-model=kernel \
+ -relocation-model=static \
+ $(_S_:R).ll
+.endfor
+
# Make the kernel depend on all the object files.
$(KERNEL): $(OBJS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment