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
30 changes: 30 additions & 0 deletions .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,33 @@ jobs:
run: flutter pub get
- name: Run tests
run: flutter test

shader-bundle-smoke-master:
name: Shader bundle smoke (master)
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: master
- run: flutter --version
- name: Verify Flutter master shader bundle hook behavior
run: tool/verify_shader_bundle_hook.sh
env:
VERIFY_BUILD_HOOK_CACHE: true
VERIFY_DIRECT_SHADER: true
VERIFY_TRANSITIVE_INCLUDE: true

shader-bundle-smoke-stable:
name: Shader bundle smoke (stable)
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
- run: flutter --version
- name: Verify Flutter stable shader bundle build compatibility
run: tool/verify_shader_bundle_hook.sh
13 changes: 13 additions & 0 deletions test_fixtures/shader_bundle_app/hook/build.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter_gpu_shaders/build.dart';
import 'package:hooks/hooks.dart';

void main(List<String> args) async {
await build(args, (input, output) async {
await buildShaderBundleJson(
buildInput: input,
buildOutput: output,
manifestFileName: 'test_bundle.shaderbundle.json',
includeDirectories: [input.packageRoot.resolve('shaders/')],
);
});
}
5 changes: 5 additions & 0 deletions test_fixtures/shader_bundle_app/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:flutter/widgets.dart';

void main() {
runApp(const SizedBox.shrink());
}
16 changes: 16 additions & 0 deletions test_fixtures/shader_bundle_app/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: shader_bundle_app
description: Fixture app for exercising flutter_gpu_shaders build hooks.
publish_to: none

environment:
sdk: ^3.10.0

dependencies:
flutter:
sdk: flutter
flutter_gpu_shaders:
path: ../..
hooks: ^2.0.0

flutter:
uses-material-design: true
3 changes: 3 additions & 0 deletions test_fixtures/shader_bundle_app/shaders/shared_color.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vec4 sharedColor() {
return vec4(0.1, 0.2, 0.3, 1.0);
}
9 changes: 9 additions & 0 deletions test_fixtures/shader_bundle_app/shaders/smoke.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#version 460 core

#include <shared_color.glsl>

out vec4 frag_color;

void main() {
frag_color = sharedColor();
}
7 changes: 7 additions & 0 deletions test_fixtures/shader_bundle_app/shaders/smoke.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#version 460 core

in vec2 position;

void main() {
gl_Position = vec4(position, 0.0, 1.0);
}
10 changes: 10 additions & 0 deletions test_fixtures/shader_bundle_app/test_bundle.shaderbundle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"SmokeVertex": {
"type": "vertex",
"file": "shaders/smoke.vert"
},
"SmokeFragment": {
"type": "fragment",
"file": "shaders/smoke.frag"
}
}
95 changes: 95 additions & 0 deletions tool/verify_shader_bundle_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env bash
set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
fixture_source="$repo_root/test_fixtures/shader_bundle_app"
verify_build_hook_cache="${VERIFY_BUILD_HOOK_CACHE:-false}"
verify_direct_shader="${VERIFY_DIRECT_SHADER:-false}"
verify_transitive_include="${VERIFY_TRANSITIVE_INCLUDE:-false}"
workdir="$(mktemp -d)"
trap 'rm -rf "$workdir"' EXIT

fixture="$workdir/shader_bundle_app"
cp -R "$fixture_source" "$fixture"

cat > "$fixture/pubspec_overrides.yaml" <<YAML
dependency_overrides:
flutter_gpu_shaders:
path: "$repo_root"
YAML

cd "$fixture"

flutter --version
flutter pub get

flutter build bundle
bundle="build/shaderbundles/test_bundle.shaderbundle"
if [[ ! -s "$bundle" ]]; then
echo "Expected shader bundle at $bundle" >&2
exit 1
fi

if [[ "$verify_build_hook_cache" != "true" ]]; then
exit 0
fi

second_build_log="$workdir/second_build.log"
flutter build bundle -v > "$second_build_log" 2>&1
if ! grep -q "Skipping target: build_hooks" "$second_build_log"; then
echo "Expected unchanged build to skip build_hooks." >&2
cat "$second_build_log" >&2
exit 1
fi

if [[ "$verify_direct_shader" != "true" ]]; then
exit 0
fi

cat > shaders/smoke.frag <<'GLSL'
#version 460 core

#include <shared_color.glsl>

out vec4 frag_color;

void main() {
frag_color = vec4(0.4, 0.5, 0.6, 1.0);
}
GLSL

third_build_log="$workdir/third_build.log"
flutter build bundle -v > "$third_build_log" 2>&1
if ! grep -q "build_hooks: Starting due to" "$third_build_log"; then
echo "Expected editing a directly declared shader to rerun build_hooks." >&2
cat "$third_build_log" >&2
exit 1
fi

if [[ ! -s "$bundle" ]]; then
echo "Expected shader bundle at $bundle after direct shader rebuild" >&2
exit 1
fi

if [[ "$verify_transitive_include" != "true" ]]; then
exit 0
fi

cat > shaders/shared_color.glsl <<'GLSL'
vec4 sharedColor() {
return vec4(0.9, 0.8, 0.7, 1.0);
}
GLSL

fourth_build_log="$workdir/fourth_build.log"
flutter build bundle -v > "$fourth_build_log" 2>&1
if ! grep -q "build_hooks: Starting due to" "$fourth_build_log"; then
echo "Expected editing a transitive #include to rerun build_hooks." >&2
cat "$fourth_build_log" >&2
exit 1
fi

if [[ ! -s "$bundle" ]]; then
echo "Expected shader bundle at $bundle after transitive include rebuild" >&2
exit 1
fi
Loading