Skip to content

Commit

Permalink
Fix publishing of newer drawing modules
Browse files Browse the repository at this point in the history
Rename generated api bindings, which are not the
initial version of this API bindings.
This allows us to easily exclude those files from
publishing.
We still want to keep the full generated files in our
VCS since it allows us to track changes, and update
the modules containing the newly added apis for
a given feature level.

Signed-off-by: Jonathan Schwender <[email protected]>
Signed-off-by: Jonathan Schwender <[email protected]>
  • Loading branch information
jschwe committed Jul 18, 2024
1 parent 7e208ae commit 28cf1dc
Show file tree
Hide file tree
Showing 34 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/drawing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "Bindings to the `native_drawing` API of OpenHarmony OS"
license = "Apache-2.0"
repository = "https://github.com/openharmony-rs/ohos-sys"
keywords = ["OpenHarmony", "HarmonyOS", "ffi", "drawing"]
exclude = ["src/**/*_api11.rs", "src/**/*_api12.rs"]
exclude = ["src/**/*_nopublish.rs"]

[dependencies]
document-features = { version = "0.2", optional = true }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 16 additions & 3 deletions scripts/generate_bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export CLANG_PATH=${OHOS_NDK_HOME}/llvm/bin/clang

OHOS_API_VERSION=$(jq '.apiVersion' -j < "${OHOS_NDK_HOME}/oh-uni-package.json")
echo "Generating bindings for API version ${OHOS_API_VERSION}"
PREVIOUS_API_VERSION=$((OHOS_API_VERSION - 1))

BASE_BINDGEN_ARGS=(--no-layout-tests --formatter=prettyplease --merge-extern-blocks)
BASE_BINDGEN_ARGS+=(--blocklist-file='.*stdint\.h' --blocklist-file='.*stddef\.h')
Expand Down Expand Up @@ -149,8 +150,9 @@ for abs_drawing_header in "${OHOS_SYSROOT_DIR}/usr/include/native_drawing"/* ; d
echo "Generating bindings for ${drawing_header}"
rust_name=${drawing_header#"drawing_"}
rust_name=${rust_name%".h"}
if [ ! -d "${ROOT_DIR}/src/drawing/${rust_name}" ]; then
mkdir "${ROOT_DIR}/src/drawing/${rust_name}"
output_dir="${ROOT_DIR}/components/drawing/src/${rust_name}"
if [ ! -d "${output_dir}" ]; then
mkdir "${output_dir}"
fi
rs_includes=()
if [[ "${rust_name}" != "types" ]]; then
Expand All @@ -161,6 +163,16 @@ for abs_drawing_header in "${OHOS_SYSROOT_DIR}/usr/include/native_drawing"/* ; d
echo "Have additional args!"
rs_includes+=( "${!additional_args_var_name}" )
fi
# We want to commit all generated files to version control, so we can easily see if something changed,
# when updating bindgen or the SDK patch release.
# However, we any split changes into incremental modules, and don't use any of the newer versions of the API
# besides the first one. If a binding was not introduced in the current api version, then we add a nopublish
# suffix, so we can exclude the file from cargo publish and save some download bandwidth.
no_publish_suffix=""
if [[ -f "${output_dir}/${rust_name}_api${PREVIOUS_API_VERSION}.rs"
|| -f "${output_dir}/${rust_name}_api${PREVIOUS_API_VERSION}_nopublish.rs" ]]; then
no_publish_suffix="_nopublish"
fi

# Some drawing headers are not valid C, so we need to use libclang in c++ mode.
# Note: block-listing `^std_.*` doesn't seem to work, perhaps the underscore replaces some other character.
Expand All @@ -170,7 +182,7 @@ for abs_drawing_header in "${OHOS_SYSROOT_DIR}/usr/include/native_drawing"/* ; d
--no-recursive-allowlist \
"${rs_includes[@]}" \
"${DRAWING_NOCOPY_ARGS[@]}" \
--output "${ROOT_DIR}/components/drawing/src/${rust_name}/${rust_name}_api${OHOS_API_VERSION}.rs" \
--output "${output_dir}/${rust_name}_api${OHOS_API_VERSION}${no_publish_suffix}.rs" \
"${OHOS_SYSROOT_DIR}/usr/include/native_drawing/${drawing_header}" \
-- "${BASE_CLANG_ARGS[@]}" \
-x c++ \
Expand All @@ -181,3 +193,4 @@ done

cargo fmt
fd -e rs . 'src/' --exec rustfmt
fd -e rs . 'components' --exec rustfmt

0 comments on commit 28cf1dc

Please sign in to comment.