Skip to content

Commit

Permalink
Add helper crate to generate syscalls.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Dec 15, 2021
1 parent dcd2854 commit 8d22ca5
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 15 deletions.
8 changes: 7 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ members = [
"programs/address-lookup-table",
"programs/address-lookup-table-tests",
"programs/bpf_loader",
"programs/bpf_loader/gen-syscall-list",
"programs/compute-budget",
"programs/config",
"programs/stake",
Expand Down
5 changes: 4 additions & 1 deletion cargo-build-bpf
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ for a in "$@"; do
fi
done

set -x
set -ex
if [[ ! -f sdk/bpf/syscalls.txt ]]; then
"$here"/cargo build --manifest-path "$here"/programs/bpf_loader/gen-syscall-list/Cargo.toml
fi
exec "$here"/cargo run --manifest-path "$here"/sdk/cargo-build-bpf/Cargo.toml -- $maybe_bpf_sdk "$@"
1 change: 0 additions & 1 deletion programs/bpf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions programs/bpf_loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ homepage = "https://solana.com/"
documentation = "https://docs.rs/solana-bpf-loader-program"
edition = "2021"

[build-dependencies]
regex = "1.5.4"

[dependencies]
bincode = "1.3.3"
byteorder = "1.4.3"
Expand Down
9 changes: 9 additions & 0 deletions programs/bpf_loader/gen-syscall-list/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "gen-syscall-list"
version = "1.10.0"
edition = "2021"
license = "Apache-2.0"
publish = false

[build-dependencies]
regex = "1.5.4"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use {
fs::File,
io::{prelude::*, BufWriter, Read},
path::PathBuf,
process::exit,
str,
},
};
Expand All @@ -15,18 +14,24 @@ use {
* to verify undefined symbols in a .so module that cargo-build-bpf has built.
*/
fn main() {
let path = PathBuf::from("src/syscalls.rs");
let mut file = match File::open(&path) {
let syscalls_rs_path = PathBuf::from("../src/syscalls.rs");
let syscalls_txt_path = PathBuf::from("../../../sdk/bpf/syscalls.txt");
println!(
"cargo:warning=(not a warning) Generating {1} from {0}",
syscalls_rs_path.display(),
syscalls_txt_path.display()
);

let mut file = match File::open(&syscalls_rs_path) {
Ok(x) => x,
_ => exit(1),
Err(err) => panic!("Failed to open {}: {}", syscalls_rs_path.display(), err),
};
let mut text = vec![];
file.read_to_end(&mut text).unwrap();
let text = str::from_utf8(&text).unwrap();
let path = PathBuf::from("../../sdk/bpf/syscalls.txt");
let file = match File::create(&path) {
let file = match File::create(&syscalls_txt_path) {
Ok(x) => x,
_ => exit(1),
Err(err) => panic!("Failed to create {}: {}", syscalls_txt_path.display(), err),
};
let mut out = BufWriter::new(file);
let sysc_re = Regex::new(r#"register_syscall_by_name\([[:space:]]*b"([^"]+)","#).unwrap();
Expand Down
3 changes: 3 additions & 0 deletions programs/bpf_loader/gen-syscall-list/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
/* I do all my work in `../build.rs` */
}
8 changes: 6 additions & 2 deletions scripts/cargo-install-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,12 @@ if [[ -d target/perf-libs ]]; then
cp -a target/perf-libs "$installDir"/bin/perf-libs
fi

mkdir -p "$installDir"/bin/sdk/bpf
cp -a sdk/bpf/* "$installDir"/bin/sdk/bpf
if [[ -z "$validatorOnly" ]]; then
# shellcheck disable=SC2086 # Don't want to double quote $rust_version
"$cargo" $maybeRustVersion build --manifest-path programs/bpf_loader/gen-syscall-list/Cargo.toml
mkdir -p "$installDir"/bin/sdk/bpf
cp -a sdk/bpf/* "$installDir"/bin/sdk/bpf
fi

(
set -x
Expand Down

0 comments on commit 8d22ca5

Please sign in to comment.