Skip to content

Commit

Permalink
Make gl46 reproducable (#312)
Browse files Browse the repository at this point in the history
* Update generate-native to reproduce gl46

Signed-off-by: sagudev <[email protected]>

* Add lint CI

Signed-off-by: sagudev <[email protected]>

---------

Signed-off-by: sagudev <[email protected]>
  • Loading branch information
sagudev authored Oct 22, 2024
1 parent 9938c26 commit e95ace4
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 178 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,20 @@ jobs:
cargo build --verbose --target aarch64-linux-android
cargo build --verbose --target armv7-linux-androideabi
cargo build --verbose --target x86_64-linux-android
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Check fmt
run: cargo fmt --check
- name: Install phosphorus from crates.io
uses: baptiste0928/cargo-install@v3
with:
crate: phosphorus
version: '0.0.22'
- name: Test reproducability of gl46.rs
run: bash generate-native.sh
- uses: infotroph/tree-is-clean@v1
with:
check_untracked: true
79 changes: 54 additions & 25 deletions generate-native.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash
mkdir -p generated
curl https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry/01ac568838ce3a93385d885362e3ddc7bca54b08/xml/gl.xml > generated/gl.xml

# phosphorus expects one API, but we're trying to generate bindings for multiple at once.
Expand All @@ -8,36 +10,63 @@ replacements+='s/name="GL_ES_VERSION_3_2"/name="GL_VERSION_4_6"/g;'
replacements+='s/number="3.2"/number="4.6"/g;'
sed --in-place $replacements generated/gl.xml

gl_extensions=(
GL_ARB_debug_output
GL_KHR_debug
GL_ARB_texture_filter_anisotropic
GL_EXT_texture_filter_anisotropic
GL_ARB_tessellation_shader
GL_ARB_compute_shader
GL_ARB_instanced_arrays
GL_EXT_draw_buffers2
GL_ARB_draw_instanced
GL_ARB_base_instance
GL_ARB_draw_elements_base_vertex
GL_ARB_framebuffer_sRGB
GL_ARB_uniform_buffer_object
GL_ARB_copy_buffer
GL_NV_copy_buffer
GL_ARB_sampler_objects
GL_ARB_buffer_storage
GL_EXT_buffer_storage
GL_ARB_vertex_array_object
GL_ARB_framebuffer_object
GL_ARB_texture_storage
GL_ARB_program_interface_query
GL_ARB_sync
GL_KHR_parallel_shader_compile
GL_ARB_parallel_shader_compile
)
printf -v gl_extensions_comma_joined '%s,' "${gl_extensions[@]}"

phosphorus \
./generated/gl.xml \
gl \
4 6 \
core \
GL_ARB_debug_output,\
GL_KHR_debug,\
GL_ARB_texture_filter_anisotropic,\
GL_EXT_texture_filter_anisotropic,\
GL_ARB_tessellation_shader,\
GL_ARB_compute_shader,\
GL_ARB_instanced_arrays,\
GL_EXT_draw_buffers2,\
GL_ARB_draw_instanced,\
GL_ARB_base_instance,\
GL_ARB_draw_elements_base_vertex,\
GL_ARB_framebuffer_sRGB,\
GL_ARB_uniform_buffer_object,\
GL_ARB_copy_buffer,\
GL_NV_copy_buffer,\
GL_ARB_sampler_objects,\
GL_ARB_buffer_storage,\
GL_EXT_buffer_storage,\
GL_ARB_vertex_array_object,\
GL_ARB_framebuffer_object,\
GL_ARB_texture_storage,\
GL_ARB_program_interface_query,\
GL_ARB_sync,\
GL_KHR_parallel_shader_compile,\
GL_ARB_parallel_shader_compile\
"${gl_extensions_comma_joined%,}" \
> generated/gl46.rs

cp generated/gl46.rs src/gl46.rs
cargo fmt
# add allow(unused)
sed -i '1 i\#!\[allow(unused)]' src/gl46.rs
# remove features for extentions
for gl_extension in "${gl_extensions[@]}"; do
sed -i '/#\[cfg(any(feature = "'"$gl_extension"'"))]/d' src/gl46.rs
sed -i '/#\[cfg_attr(docs_rs, doc(cfg(any(feature = "'"$gl_extension"'"))))]/d' src/gl46.rs
done
function remove_between() {
start_line=$(grep -wn "$1" src/gl46.rs | cut -d: -f1 | head -n 1)
end_line=$(grep -wn "$2" src/gl46.rs | cut -d: -f1 | head -n 1)
sed -i "${start_line},${end_line}d" src/gl46.rs
}
# remove unused import
remove_between '#\[cfg(feature = "chlorine")]' '#\[cfg(not(feature = "chlorine"))]'
# remove first ocurance of #[cfg(feature = "global_loader")]
remove_between '#\[cfg(feature = "global_loader")]' '#\[cfg(feature = "global_loader")]'
# remove global loader
remove_between '#\[cfg(feature = "global_loader")]' '#\[cfg(feature = "struct_loader")]'
# remove all occurances of #[cfg(feature = "struct_loader")]
sed -i '/#\[cfg(feature = "struct_loader")]/d' src/gl46.rs
cargo fmt
Loading

0 comments on commit e95ace4

Please sign in to comment.