Skip to content

Commit

Permalink
added multiple supported arch+os
Browse files Browse the repository at this point in the history
  • Loading branch information
5h4d0w4rt committed Oct 30, 2021
1 parent 12dc9b5 commit a84718d
Show file tree
Hide file tree
Showing 7 changed files with 424 additions and 221 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,18 @@ jobs:

# Runs a single command using the runners shell
- name: Build and test everything
run: bazel build //... && bazel test //...
run: bazelisk build //... && bazelisk test //...

# TODO(5h4d0w4rt) add cross-build https://github.com/marketplace/actions/run-on-architecture
build-linux:
# The type of runner that the job will run on
runs-on: ubuntu-20.04

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Runs a single command using the runners shell
- name: Build and test everything
run: bazelisk build //... && bazelisk test //...
20 changes: 14 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
workspace(name = "io_bazel_rules_prometheus")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

http_archive(
name = "platforms",
sha256 = "079945598e4b6cc075846f7fd6a9d0857c33a7afc0de868c2ccb96405225135d",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.4/platforms-0.0.4.tar.gz",
"https://github.com/bazelbuild/platforms/releases/download/0.0.4/platforms-0.0.4.tar.gz",
],
)

http_archive(
name = "bazel_skylib",
Expand All @@ -11,12 +21,6 @@ http_archive(
],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "io_bazel_stardoc",
commit = "4378e9b6bb2831de7143580594782f538f461180",
Expand All @@ -28,6 +32,10 @@ load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("@io_bazel_rules_prometheus//:deps.bzl", "prometheus_repositories")

prometheus_repositories()
53 changes: 17 additions & 36 deletions prometheus/internal/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load(":toolchain.bzl", "declare_toolchains_dummy", "declare_toolchains_prod")
load(":toolchain.bzl", "declare_toolchains")
load(":platforms.bzl", "declare_constraints")

package(
default_visibility = [
Expand Down Expand Up @@ -42,49 +43,29 @@ bzl_library(
srcs = ["providers.bzl"],
)

bzl_library(
name = "platforms",
srcs = ["platforms.bzl"],
)

bzl_library(
name = "toolchain",
srcs = ["toolchain.bzl"],
deps = [":providers"],
deps = [
":platforms",
":providers",
],
)

bzl_library(
name = "repositories",
srcs = ["repositories.bzl"],
deps = [":toolchain"],
deps = [
":platforms",
":toolchain",
],
)

declare_toolchains_prod(
architectures = (
"darwin-amd64",
),
)
declare_constraints()

declare_toolchains_dummy(
architectures = (
"dragonfly-amd64",
"freebsd-386",
"freebsd-amd64",
"freebsd-armv6",
"freebsd-armv7",
"linux-386",
"linux-amd64",
"linux-arm64",
"linux-armv5",
"linux-armv6",
"linux-armv7",
"linux-mips64",
"linux-mips64le",
"linux-ppc64",
"linux-ppc64le",
"linux-s390x",
"netbsd-386",
"netbsd-amd64",
"netbsd-armv6",
"netbsd-armv7",
"openbsd-386",
"openbsd-amd64",
"windows-386",
"windows-amd64",
),
)
declare_toolchains()
117 changes: 117 additions & 0 deletions prometheus/internal/platforms.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
INCOMPATIBLE = "@platforms//:incompatible"

This comment has been minimized.

Copy link
@seh

seh Oct 30, 2021

Did you wind up using this anywhere? It sounds like a solution to the problem that motivated me to introduce that "phantom" constraint setting with value "nonexistent."


_LIST_OF_PLATFORMS = (
"darwin-amd64",
"darwin-arm64",
"dragonfly-amd64",
"freebsd-386",
"freebsd-amd64",
"freebsd-arm64",
"freebsd-armv6",
"freebsd-armv7",
"illumos-amd64",
"linux-386",
"linux-amd64",
"linux-arm64",
"linux-armv5",
"linux-armv6",
"linux-armv7",
"linux-mips",
"linux-mips64",
"linux-mips64le",
"linux-mipsle",
"linux-ppc64",
"linux-ppc64le",
"linux-s390x",
"netbsd-386",
"netbsd-amd64",
"netbsd-arm64",
"netbsd-armv6",
"netbsd-armv7",
"openbsd-386",
"openbsd-amd64",
"openbsd-arm64",
"openbsd-armv7",
"windows-386",
"windows-amd64",
)

PrometheusPlatformsInfo = provider(
# this should store os-arch combinations for toolchain generation
doc = "OS and CPU platforms, constraints and available architectures metadata provider",
fields = {
"platforms": "mapping of PrometheusPlatformInfo providers",
"available_platforms": "list of platforms",
},
)

PrometheusPlatformInfo = provider(
# this should store os-arch combinations for toolchain generation
doc = "OS and CPU platform constraints metadata provider",
fields = [
"os",
"cpu",
],
)

OsConstraintsInfo = struct(
darwin = "@platforms//os:osx",
freebsd = "@platforms//os:freebsd",
dragonfly = "@platforms//os:freebsd",
linux = "@platforms//os:linux",
windows = "@platforms//os:windows",
netbsd = "@platforms//os:freebsd",
openbsd = "@platforms//os:openbsd",
illumos = "@platforms//os:openbsd",
)

CpuConstraintsInfo = struct(
amd64 = "@platforms//cpu:x86_64",
arm = "@platforms//cpu:arm",
arm64 = "@platforms//cpu:arm64",
armv5 = "@platforms//cpu:arm",
armv6 = "@platforms//cpu:arm",
armv7 = "@platforms//cpu:armv7",
mips64 = "@platforms//cpu:mips64",
mips64le = "@platforms//cpu:mips64",
ppc64 = "@platforms//cpu:x86_32",
ppc64le = "@platforms//cpu:ppc",
s390x = "@platforms//cpu:s390x",
mips = "@platforms//cpu:x86_32",
mipsle = "@platforms//cpu:x86_32",
# because you can't pass integer as keyword in python
**{"386": "@platforms//cpu:x86_32"}
)

def platform_info_factory(list_of_platforms):
return PrometheusPlatformsInfo(
available_platforms = list_of_platforms,
platforms = struct(**{
platform: PrometheusPlatformInfo(
os = platform.partition("-")[0],
cpu = platform.partition("-")[-1],
)
for platform in list_of_platforms
}),
)

PLATFORMS = platform_info_factory(
_LIST_OF_PLATFORMS,

This comment has been minimized.

Copy link
@seh

seh Oct 30, 2021

Does this eliminate the previous distinction between "prod" and "dummy" architectures? Are they all available now? If not, what determines which of the known ones are available and which are not?

)

def declare_constraints(_platforms_info = PLATFORMS):
"""Generates constraint_values and platform targets for valid platforms.
Args:
_platforms_info: pre-built PrometheusPlatformInfo provider with info on all available os+architectures
"""

for platform in _platforms_info.available_platforms:
platform_info = getattr(_platforms_info.platforms, platform)

native.platform(
name = "prometheus_platform_{platform}".format(platform = platform),
constraint_values = [
getattr(OsConstraintsInfo, platform_info.os),
getattr(CpuConstraintsInfo, platform_info.cpu),
],
)
18 changes: 18 additions & 0 deletions prometheus/internal/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,21 @@ AmtoolStubInfo = provider(
},
)
AmtoolInfo = AmtoolStubInfo

PrometheusPlatformsInfo = provider(
# this should store os-arch combinations for toolchain generation
doc = "OS and CPU platforms, constraints and available architectures metadata provider",
fields = {
"platforms": "mapping of PrometheusPlatformInfo providers",
"available_platforms": "list of platforms",
},
)

PrometheusPlatformInfo = provider(
# this should store os-arch combinations for toolchain generation
doc = "OS and CPU platform constraints metadata provider",
fields = [
"os",
"cpu",
],
)
Loading

0 comments on commit a84718d

Please # to comment.