Skip to content

Commit

Permalink
Add acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vertexwahn committed Oct 8, 2023
1 parent 8d6d4bf commit 83db957
Show file tree
Hide file tree
Showing 25 changed files with 528 additions and 8 deletions.
2 changes: 2 additions & 0 deletions intermediate/cpp/GPU/OpenGL/EmscriptenGLFW/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#

#build --symlink_prefix=/ # Out of source build

# Bzlmod
common --enable_bzlmod # default in Bazel 7.0

# GCC 9.3
Expand Down
1 change: 0 additions & 1 deletion intermediate/cpp/GPU/OpenGL/EmscriptenGLFW/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ cc_binary(
"-s NO_EXIT_RUNTIME=0",
"-s ASSERTIONS=1",
],
#data = ["index.html"],
tags = ["manual"],
)

Expand Down
1 change: 0 additions & 1 deletion intermediate/cpp/GPU/OpenGL/EmscriptenGLFW/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ Visit http://localhost:8000/index.html

#### Docker


```shell
# Create an image
bazel run //:tarball
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# SPDX-License-Identifier: Apache-2.0
#

# Bzlmod
common --enable_bzlmod # default in Bazel 7.0

# GCC 9.3
build:gcc9 --cxxopt=-std=c++2a
build:gcc9 --cxxopt=-Wall
Expand Down
75 changes: 70 additions & 5 deletions intermediate/cpp/GPU/WebGPU/webgpu-cross-platform-app/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@rules_go//go:def.bzl", "go_binary")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
load("@rules_pkg//:mappings.bzl", "pkg_files")
load("@rules_pkg//:pkg.bzl", "pkg_tar")

cc_binary(
name = "index",
name = "emscripten_main",
srcs = [
"main.cpp",
],
Expand All @@ -19,10 +23,14 @@ cc_binary(
)

wasm_cc_binary(
name = "index-wasm",
cc_target = ":index",
name = "emscripten_main_wasm",
cc_target = ":emscripten_main",
)

#-------------------------------------------------------------------------------------
# Desktop App
#-------------------------------------------------------------------------------------

cc_binary(
name = "main",
srcs = [
Expand All @@ -37,4 +45,61 @@ cc_binary(
"@platforms//os:windows": [],
"@bazel_tools//src/conditions:darwin": [],
}),
)
)

#-------------------------------------------------------------------------------------
# Docker Container
#-------------------------------------------------------------------------------------

pkg_files(
name = "dir_static",
srcs = [
":emscripten_main_wasm",
"//ui/static",
],
prefix = "ui/static",
)

#config_setting(
# name = "osx_arm64",
# constraint_values = [
# "@platforms//os:osx",
# "@platforms//cpu:aarch64",
# ],
#)

go_binary(
name = "app",
srcs = ["main.go"],
data = [
":dir_static",
],
goarch = "amd64", #"arm64", # switch to you architecture
# Cannot use select for go_binary with goos/goarch set, but {} was a select
#goarch = select({
# ":osx_arm64": "arm64",
# "//conditions:default": "amd64",
#}),
goos = "linux",
)

pkg_tar(
name = "app_layer",
srcs = [
":app",
":dir_static",
],
)

oci_image(
name = "image",
base = "@distroless_base",
entrypoint = ["/app"],
tars = [":app_layer"],
)

oci_tarball(
name = "tarball",
image = ":image",
repo_tags = ["vertexwahn/emscripten_webgpu:v0.0.1"],
)
75 changes: 75 additions & 0 deletions intermediate/cpp/GPU/WebGPU/webgpu-cross-platform-app/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""
SPDX-FileCopyrightText: 2023 Julian Amann <[email protected]>
SPDX-License-Identifier: Apache-2.0
"""

bazel_dep(name = "gazelle", version = "0.32.0")
bazel_dep(name = "platforms", version = "0.0.7")
bazel_dep(name = "rules_cc", version = "0.0.8")
bazel_dep(name = "rules_go", version = "0.41.0")
bazel_dep(name = "rules_oci", version = "1.3.2")
bazel_dep(name = "rules_pkg", version = "0.9.1")

#-------------------------------------------------------------------------------------
# Go
#-------------------------------------------------------------------------------------

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(
name = "go_sdk",
version = "1.21.0",
)
use_repo(go_sdk, "go_sdk")

register_toolchains("@go_sdk//:all")

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")

#-------------------------------------------------------------------------------------
# Python
#-------------------------------------------------------------------------------------

bazel_dep(name = "rules_python", version = "0.25.0")

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
use_repo(python, "python_versions")

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "my_deps",
python_version = "3.11",
requirements_lock = "//:requirements.txt",
)
use_repo(pip, "my_deps")

#-------------------------------------------------------------------------------------
# rules_oci
#-------------------------------------------------------------------------------------

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci.toolchains(crane_version = "v0.14.0")
use_repo(oci, "oci_auth_config", "oci_crane_registry_toolchains", "oci_crane_toolchains")

register_toolchains("@oci_crane_toolchains//:all", "@oci_crane_registry_toolchains//:all")

oci.pull(
name = "ubuntu",
digest = "sha256:67211c14fa74f070d27cc59d69a7fa9aeff8e28ea118ef3babc295a0428a6d21",
image = "ubuntu",
platforms = [
"linux/arm64/v8",
"linux/amd64",
],
)
use_repo(oci, "ubuntu")
oci.pull(
name = "distroless_base",
digest = "sha256:ccaef5ee2f1850270d453fdf700a5392534f8d1a8ca2acda391fbb6a06b81c86",
image = "gcr.io/distroless/base",
platforms = [
"linux/amd64",
"linux/arm64",
],
)
use_repo(oci, "distroless_base")
24 changes: 23 additions & 1 deletion intermediate/cpp/GPU/WebGPU/webgpu-cross-platform-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@
https://developer.chrome.com/blog/webgpu-cross-platform/
https://github.com/beaufortfrancois/webgpu-cross-platform-app

## macOS

```shell
# Create an image
bazel run //:tarball
# Run docker container and delete it on quit
docker run -p 4059:4000 vertexwahn/emscripten_webgpu:v0.0.1
```

Visit http://localhost:4059/static/index2.html

## Ubuntu 22.04

#### Docker

```shell
# Create an image
bazel run //:tarball
# Run docker container and delete it on quit
docker run -p 4059:4000 vertexwahn/emscripten_webgpu:v0.0.1
```

Visit http://localhost:4059/static/index2.html

### Web

Expand All @@ -14,7 +37,6 @@ cd $bazel_genfiles/index-wasm/
python3 -m http.server
```


1. Goal:

Should run on Windows and look like this:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
common --enable_bzlmod # default in Bazel 7.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.3.2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel-*
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load("@io_bazel_rules_webtesting//web:py.bzl", "py_web_test_suite")
load("@my_deps//:requirements.bzl", "requirement")

py_web_test_suite(
name = "browser_test",
srcs = ["browser_test.py"],
browsers = [
"@io_bazel_rules_webtesting//browsers:chromium-local",
],
data = [
"ref_screenshot2.png",
],
local = True,
deps = [
"@io_bazel_rules_webtesting//testing/web",
requirement("imagehash"),
],
)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# How to run acceptance test

Those test work only on a single Ubuntu 22.04 system:

![works on my machine](works_on_my_machine.webp)

## MacOS

```bash
bazel build //... # fails currently on macOS (tested on M1) - not sure why...
```

## Ubuntu 22.04

```bash
bazel test //...
```

## References

- [Bazel Web Testing Rules](https://docs-legacy.aspect.build/bazelbuild/rules_webtesting/0.3.5/readme)
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Python first

SHA = "5868e73107a8e85d8f323806e60cad7283f34b32163ea6ff1020cf27abef6036"

VERSION = "0.25.0"

http_archive(
name = "rules_python",
sha256 = SHA,
strip_prefix = "rules_python-{}".format(VERSION),
url = "https://github.com/bazelbuild/rules_python/releases/download/{}/rules_python-{}.tar.gz".format(VERSION, VERSION),
)

load("@rules_python//python:repositories.bzl", "py_repositories")

py_repositories()

http_archive(
name = "io_bazel_rules_webtesting",
sha256 = "41d500a97ad9621dcf92fcb0cd77916e517388b196e5c3f0e63c7753e983b2bb",
strip_prefix = "rules_webtesting-4d7ec75d1cbb289f977b41638fc8b630bdf22bee",
urls = [
"https://github.com/bazelbuild/rules_webtesting/archive/4d7ec75d1cbb289f977b41638fc8b630bdf22bee/rules_webtesting.tar.gz",
],
)

load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories")

web_test_repositories()

http_archive(
name = "io_bazel_rules_go",
sha256 = "278b7ff5a826f3dc10f04feaf0b70d48b68748ccd512d7f98bf442077f043fe3",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.41.0/rules_go-v0.41.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.41.0/rules_go-v0.41.0.zip",
],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.20.5")

http_archive(
name = "bazel_gazelle",
sha256 = "29218f8e0cebe583643cbf93cae6f971be8a2484cdcfa1e45057658df8d54002",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.32.0/bazel-gazelle-v0.32.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.32.0/bazel-gazelle-v0.32.0.tar.gz",
],
)

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

gazelle_dependencies()

load("@io_bazel_rules_webtesting//web/versioned:browsers-0.3.4.bzl", "browser_repositories")

browser_repositories(
chromium = True,
#firefox = True,
#sauce = True,
)

load("@io_bazel_rules_webtesting//web:go_repositories.bzl", "go_internal_repositories", "go_repositories")

go_repositories()

go_internal_repositories()

load("@io_bazel_rules_webtesting//web:py_repositories.bzl", "py_repositories")

py_repositories()

load("@io_bazel_rules_webtesting//web:java_repositories.bzl", "java_repositories")

java_repositories()

load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse(
name = "my_deps",
requirements_lock = "//:requirements.txt",
)

# Load the starlark macro, which will define your dependencies.
load("@my_deps//:requirements.bzl", "install_deps")

# Call it to define repos for your requirements.
install_deps()
Loading

0 comments on commit 83db957

Please sign in to comment.