Skip to content

Commit

Permalink
Adds build.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed May 5, 2024
1 parent 508a834 commit 1984a28
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[build]
target = "x86_64-unknown-none"

[unstable]
build-std = ["std", "panic_abort"]
build-std-features = ["panic_immediate_abort"]
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ jobs:
run: cargo fmt --check
- name: Install Rust components
run: rustup component add rust-src llvm-tools
- name: Install Cargo commands
run: cargo install --git https://github.com/rust-embedded/cargo-binutils.git
- name: Build
run: cargo objcopy -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --release release -- -O binary kernel-dumper.bin
run: ./build.py
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/Cargo.lock
/kernel-dumper.bin
/target/
16 changes: 2 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,13 @@ The value for `Base Address` is `VirtAddr` of the first `LOAD` program (e.g. `0x
### Install additional Rust component

```sh
rustup component add rust-src
```

### Install additional Cargo commands

```sh
cargo install --git https://github.com/rust-embedded/cargo-binutils.git
```

`cargo-binutils` required additional dependency which can be installed with the following command:

```sh
rustup component add llvm-tools
rustup component add rust-src llvm-tools
```

### Build

```sh
cargo objcopy -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --release release -- -O binary kernel-dumper.bin
./build.py
```

## License
Expand Down
21 changes: 21 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
import json
from subprocess import Popen, PIPE, run
import sys

# Build.
with Popen(["cargo", "build", "-r", "--message-format", "json-render-diagnostics"], stdout=PIPE) as proc:
for line in proc.stdout:
line = json.loads(line)
reason = line["reason"]
if reason == "build-finished":
if line["success"]:
break
else:
sys.exit(1)
elif reason == "compiler-artifact":
if line["target"]["name"] == "kernel-dumper":
out = line["executable"]

# Create payload.
run(["rustup", "run", "nightly", "objcopy", "-O", "binary", out, "kernel-dumper.bin"], check=True)

0 comments on commit 1984a28

Please sign in to comment.