Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions perf-event-open-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,11 @@ features are added at a steady pace. To update the generated bindings:
actually affect the API at all, and even those that do may not require a new
major version.

If an update adds a field to a struct, we should treat that as a breaking
change. As explained in the module documentation, properly written user
crates should not be affected, but it seems unnecessary to risk `cargo
update` breaking builds. When users need new functionality from the
bindings, they can update the major version number of this crate they
request.

- Fix the comments in `src/lib.rs` explaining exactly which version of the
kernel headers you generated the bindings from.
You can use [`cargo-semver-checks`][semchecks] in order to verify that the
resulting changes are semver-compatible. We don't always literally follow
the standards set by cargo-semver-checks (e.g. some changes to
`perf_event_attr` are actually fine) but it is generally a good starting
point for determining whether the change is a breaking one.

[bindgen]: https://crates.io/crates/bindgen
[semchecks]: https://github.com/obi1kenobi/cargo-semver-checks
7 changes: 7 additions & 0 deletions perf-event-open-sys/RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Release notes for `perf-event-open-sys`

## Unreleased

- All bindings have been regenerated from the headers for Linux v6.13.9.

- The bindings no longer include a large number of types and constants that
are not related to `perf_event_open`.

## 5.0.0

- Regenerated `x86_64` bindings from Fedora's
Expand Down
124 changes: 124 additions & 0 deletions perf-event-open-sys/regenerate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/usr/bin/env bash

set -eu

cd "$(dirname "$0")"

# Adding a new architecture
# =========================
# In order to add bindings for a new architecture you will need the arch name
# as used in
# - the linux architecture name,
# - the rustc target triple, and,
# - the clang target triple.
#
# For some architectures (e.g. x86_64) this will all be the same. For others,
# (e.g. RISC-V) they will all be different.
#
# Here's how to find each one:
# - For rustc, look at the supported target triples in the documentation here:
# https://doc.rust-lang.org/nightly/rustc/platform-support.html
# - Linux has its own architecture naming scheme. See the page below for a
# command which generates a list:
# https://docs.kernel.org/kbuild/headers_install.html
# - For Clang, there doesn't seem to be one place that lists all of the
# supported architectures. It may be necessary to do some research here.
# A small list is available at:
# https://clang.llvm.org/docs/CrossCompilation.html#target-triple
#
# Once you have these, add a new gen_bindings command that passes in the arch
# names.
#
# As an example, the command for riscv64 would look like this:
#
# gen_bindings riscv64gc riscv riscv64
#
# Updating the linux kernel version
# =================================
# The full kernel version used is specified right here:
version=6.13.9
#
# In order to generate bindings for a different kernel change the version and
# rerun the script. See https://kernel.org/ to find available kernel versions.
# This script will take care of downloading the new kernel tarball, extracting
# it, and then using that kernel to generate the bindings.

series="v$(echo $version | cut -d . -f 1).x"

scriptdir="$PWD"
targetdir="$(cargo metadata --format-version 1 | jq -r .target_directory)"
target="$targetdir/linux"

mkdir -p "$target"

if ! [ -f "$target/linux-$version.tar.xz" ]; then
wget "https://cdn.kernel.org/pub/linux/kernel/$series/linux-$version.tar.xz" \
-O "$target/linux-$version.tar.xz"
fi

if ! [ -d "$target/linux-$version" ]; then
tar xf "$target/linux-$version.tar.xz" -C "$target"
fi

function gen_bindings {
arch="$1"
linux_arch="${2:-$arch}"
clang_arch="${3:-$arch}"

bindings="$target/$arch/bindings.rs"

echo "Generating $arch bindings"

rm -rf "${target:?}/$arch"
mkdir -p "$target/$arch"
cd "$target/linux-$version"
make headers_install ARCH="$linux_arch" INSTALL_HDR_PATH="$target/$arch" > /dev/null
cd "$scriptdir"

CLANG_ARGS=(
-target "$clang_arch-unknown-linux-gnu"
-nostdlibinc
-isystem "$target/$arch/include"
)

# This ensures we get errors from clang instead of bindgen panicking with
# no useful error message.
#
# We don't actually use the output from here though.
clang "${CLANG_ARGS[@]}" \
-E wrapper.h \
-o "$target/$arch/wrapper.i"

BINDGEN_ARGS=(
--impl-debug
--with-derive-default
--no-prepend-enum-name

# This ends up being a needless changed line when updating bindgen
# versions.
--disable-header-comment

--allowlist-var 'PERF_.*'
--allowlist-var '__NR_perf_event_open'
--allowlist-var '[A-Z]+_NS_INDEX'
--allowlist-var 'HW_BREAKPOINT_[A-Z0-9_]+'

--allowlist-type 'perf_.*'
)

bindgen "${BINDGEN_ARGS[@]}" \
--output "$bindings" \
wrapper.h \
-- \
"${CLANG_ARGS[@]}"

cat src/bindings_header.rs \
"$bindings" \
> "src/bindings_$arch.rs"
}

echo "$version" > src/version

gen_bindings x86_64
gen_bindings aarch64 arm64
gen_bindings riscv64gc riscv riscv64
2 changes: 0 additions & 2 deletions perf-event-open-sys/regenerate/.gitignore

This file was deleted.

45 changes: 0 additions & 45 deletions perf-event-open-sys/regenerate/fetch-kernel-headers.sh

This file was deleted.

46 changes: 0 additions & 46 deletions perf-event-open-sys/regenerate/regenerate.sh

This file was deleted.

Loading
Loading