Skip to content

Commit

Permalink
Merge pull request #587 from roblabla/rust-patches
Browse files Browse the repository at this point in the history
New rust-lang/rust workflow based on patches
  • Loading branch information
roblabla authored Jun 6, 2020
2 parents 4e0abd8 + 3869302 commit 7d908e7
Show file tree
Hide file tree
Showing 23,637 changed files with 9,965 additions and 1,775,335 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
shell: bash

- name: Install cargo-make
run: cargo install cargo-make --version 0.22.0 --locked
run: cargo install cargo-make --version 0.31.0 --locked

- name: Install xargo
run: cargo install xargo --version 0.3.18 --locked
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ DISK.img
/*.iml
/cmake-build-debug
/link.T
/rust
137 changes: 118 additions & 19 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[config]
skip_core_tasks = true
min_version = "0.22.0"
min_version = "0.31.0"
default_to_workspace = false

[env]
Expand Down Expand Up @@ -78,91 +78,91 @@ install_crate = { crate_name = "xargo", binary = "xargo", test_arg = "--version"

[tasks.bootstrap]
description = "Compiles the i386 bootstrap"
dependencies = ["bootstrap-linker", "install-xargo"]
dependencies = ["bootstrap-linker", "install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-none", "--package=sunrise-bootstrap", "@@split(COMPILER_FLAGS, )" ]

[tasks.kernel]
description = "Compiles the kernel"
dependencies = ["kernel-linker", "install-xargo"]
dependencies = ["kernel-linker", "install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-none", "--package=sunrise-kernel", "@@split(COMPILER_FLAGS, )", "@@split(KERNEL_FLAGS, )"]

[tasks.vi]
description = "Compiles sunrise-vi"
dependencies = ["install-xargo"]
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-vi", "@@split(COMPILER_FLAGS, )"]

[tasks.sm]
description = "Compiles sunrise-sm"
dependencies = ["install-xargo"]
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-sm", "@@split(COMPILER_FLAGS, )"]

[tasks.shell]
description = "Compiles sunrise-shell"
dependencies = ["install-xargo"]
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-shell", "@@split(COMPILER_FLAGS, )"]

[tasks.wall-clock]
description = "Compiles sunrise-wall-clock"
dependencies = ["install-xargo"]
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-wall-clock", "@@split(COMPILER_FLAGS, )"]

[tasks.ahci]
description = "Compiles sunrise-ahci"
dependencies = ["install-xargo"]
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-ahci", "@@split(COMPILER_FLAGS, )"]

[tasks.time]
description = "Compiles sunrise-time"
dependencies = ["install-xargo"]
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-time", "@@split(COMPILER_FLAGS, )"]

[tasks.fs]
description = "Compiles sunrise-fs"
dependencies = ["install-xargo"]
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-fs", "@@split(COMPILER_FLAGS, )"]

[tasks.loader]
description = "Compiles sunrise-loader"
dependencies = ["install-xargo"]
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-loader", "@@split(COMPILER_FLAGS, )"]

[tasks.keyboard]
description = "Compiles sunrise-keyboard"
dependencies = ["install-xargo"]
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-keyboard", "@@split(COMPILER_FLAGS, )"]

[tasks.twili]
description = "Compiles sunrise-twili"
dependencies = ["install-xargo"]
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-twili", "@@split(COMPILER_FLAGS, )"]

[tasks.std_hello_world]
description = "Compiles std_hello_world"
dependencies = ["install-xargo"]
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=std_hello_world", "@@split(COMPILER_FLAGS, )"]

[tasks.df]
description = "Compiles df"
dependencies = ["install-xargo"]
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=df", "@@split(COMPILER_FLAGS, )"]

[tasks.uutils]
description = "Compiles uutils (coreutils)"
dependencies = ["install-xargo"]
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=uutils", "-Z", "package-features", "--features=sunrise", "--no-default-features", "@@split(COMPILER_FLAGS, )"]

Expand Down Expand Up @@ -311,7 +311,7 @@ args = ["test", "--target=i686-unknown-linux-gnu",

[tasks.clippy-sunrise-kernel-target]
description = "Run clippy on sunrise kernel and bootstrap"
dependencies = ["install-xargo"]
dependencies = ["install-xargo", "setup-rust"]
install_crate = { rustup_component_name = "clippy" }
command = "xargo"
args = ["clippy", "--target=i386-unknown-none",
Expand All @@ -324,7 +324,7 @@ args = ["clippy", "--target=i386-unknown-none",

[tasks.clippy-sunrise-userspace-target-nostd]
description = "Run clippy on sunrise userspace (no std)"
dependencies = ["install-xargo"]
dependencies = ["install-xargo", "setup-rust"]
install_crate = { rustup_component_name = "clippy" }
command = "xargo"
args = ["clippy", "--target=i386-unknown-sunrise-user",
Expand All @@ -348,7 +348,7 @@ args = ["clippy", "--target=i386-unknown-sunrise-user",

[tasks.clippy-sunrise-userspace-target-std]
description = "Run clippy on sunrise userspace (std)"
dependencies = ["install-xargo"]
dependencies = ["install-xargo", "setup-rust"]
install_crate = { rustup_component_name = "clippy" }
command = "xargo"
args = ["clippy", "--target=i386-unknown-sunrise-user",
Expand All @@ -370,6 +370,105 @@ args = ["clippy",
"${@}",
]

[tasks.setup-rust]
script_runner = "@duckscript"
script = [
'''
version = readfile rust-toolchain
date = split ${version} "-"
array_remove ${date} 0
date = array_join ${date} "-"
datetime = concat ${date} " 12:00:00 +0000"
function apply_patches
patches = glob_array ${CARGO_MAKE_WORKING_DIRECTORY}/rust-patches/*.patch
patches = array_join ${patches} " "
set_env GIT_COMMITTER_NAME patchsystem
set_env GIT_COMMITTER_EMAIL patchsystem
exec git am --committer-date-is-author-date %{patches}
end
# If rust folder doesn't exist, create it, and import the rust source.
if not is_path_exists ${CARGO_MAKE_WORKING_DIRECTORY}/rust
output = exec rustc --print sysroot
output.stdout = trim ${output.stdout}
sysroot = concat ${output.stdout} /lib/rustlib/src/rust/
cp ${sysroot} ${CARGO_MAKE_WORKING_DIRECTORY}
cd ${CARGO_MAKE_WORKING_DIRECTORY}/rust/
exec git init
exec git add .
set_env GIT_COMMITTER_NAME patchsystem
set_env GIT_COMMITTER_EMAIL patchsystem
set_env GIT_COMMITTER_DATE ${datetime}
set_env GIT_AUTHOR_NAME patchsystem
set_env GIT_AUTHOR_EMAIL patchsystem
set_env GIT_AUTHOR_DATE ${datetime}
echo "Importing rust-src"
exec git commit -m ${version} -q
unset_env GIT_AUTHOR_DATE
unset_env GIT_AUTHOR_EMAIL
unset_env GIT_AUTHOR_NAME
end
use_dirty_rust_repo = get_env USE_DIRTY_RUST_REPO
if not is_empty ${use_dirty_rust_repo}
echo "Using dirty rust repository."
exit 0
end
cd ${CARGO_MAKE_WORKING_DIRECTORY}/rust/
# Check the original commit matches the current rust version. If it doesn't,
# bail out, tell user they need to update their patches.
head_rev = exec git rev-list --max-parents=0 HEAD
head_rev = trim ${head_rev.stdout}
message = exec git log --format=%B -n 1 ${head_rev}
message = trim ${message.stdout}
assert_eq ${message} ${version} "\nRust version doesn't match rust-toolchain. The patches will need to be updated. See docs/UPDATE_RUST.md for more information."
# Check if there's any uncommitted changes. If there are, bail out, tell
# user.
exec git update-index --refresh
status = exec git status --porcelain -z
status = trim ${status.stdout}
status_empty = is_empty ${status}
assert ${status_empty} "\nUncommited changes were found in the rust folder.\nEither commit them and create a patch, or set the USE_DIRTY_RUST_REPO environment variable."
# Check if there's any commits that got changed. If there are, tell the user
# to create patches.
output = exec git log --committer=^(?!patchsystem).*$ --perl-regexp --format=oneline
output = trim ${output.stdout}
output_empty = is_empty ${output}
assert ${output_empty} "\nRust repo has commits that weren't properly added to the patch system.\nEither run create-patches, or set the USE_DIRTY_RUST_REPO environment variable."
# Every commit belongs to the patchsystem, re-applying the patches is safe.
# Reset to initial commit (which imports the rust tree)
head = exec git rev-list --max-parents=0 HEAD
head = trim ${head.stdout}
exec git reset --hard ${head}
# Apply all patches.
apply_patches
''']

[tasks.create-patches]
script_runner = "@duckscript"
script = [
'''
cd rust
# Get initial commit (which imports the rust tree)
head = exec git rev-list --max-parents=0 HEAD
head = trim ${head.stdout}
# Change committer for the previous patches so they show up as being committed
# by patchsystem.
set_env FILTER_BRANCH_SQUELCH_WARNING 1
exec git update-ref -d refs/original/refs/heads/master
exec git filter-branch --env-filter "export GIT_COMMITTER_NAME=patchsystem; export GIT_COMMITTER_EMAIL=patchsystem" -- ${head}..
# Create patch for every commit after initial commit.
exec git format-patch -o ../rust-patches ${head}..
''']

[tasks.clippy]
dependencies = ["clippy-host-target", "clippy-sunrise-kernel-target", "clippy-sunrise-userspace-target-nostd", "clippy-sunrise-userspace-target-std"]

Expand Down
4 changes: 2 additions & 2 deletions docs/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ printed on stdout.

## Versions

- rust: `nightly-2019-15-07`
- rust: `nightly-2020-05-27`
- clippy
- rust-src
- cargo-make: `0.22.0`
- cargo-make: `0.31.0`
- xargo: `0.3.18`
- mkisofs-rs: `0.1.1`
- qemu-system-i386: `4.0.50`
Expand Down
Loading

0 comments on commit 7d908e7

Please sign in to comment.