diff options
author | Guillaume Chatelet <gchatelet@google.com> | 2022-03-15 19:05:03 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-15 19:05:03 +0300 |
commit | 188d0d3c383689cdb6bb70dc6da2469faec84f61 (patch) | |
tree | cc05ee2aef8eb51f8055035d8dcb29cd40f62d32 | |
parent | c219c921c5120a5a5862bb60bb7031dc4833f6c7 (diff) |
Add bazel ci README, update main README (#235)
-rw-r--r-- | README.md | 40 | ||||
-rw-r--r-- | bazel/ci/README.md | 5 | ||||
-rw-r--r-- | cmake/ci/README.md | 26 | ||||
-rw-r--r-- | scripts/generate_badges.d | 126 |
4 files changed, 123 insertions, 74 deletions
@@ -1,18 +1,38 @@ # cpu_features -[![Linux Status][linux_svg]][linux_link] -[![Macos Status][macos_svg]][macos_link] -[![Windows Status][windows_svg]][windows_link] - -[linux_svg]: https://github.com/google/cpu_features/actions/workflows/amd64_linux.yml/badge.svg?branch=main -[linux_link]: https://github.com/google/cpu_features/actions/workflows/amd64_linux.yml -[macos_svg]: https://github.com/google/cpu_features/actions/workflows/amd64_macos.yml/badge.svg?branch=main -[macos_link]: https://github.com/google/cpu_features/actions/workflows/amd64_macos.yml -[windows_svg]: https://github.com/google/cpu_features/actions/workflows/amd64_windows.yml/badge.svg?branch=main -[windows_link]: https://github.com/google/cpu_features/actions/workflows/amd64_windows.yml A cross-platform C library to retrieve CPU features (such as available instructions) at runtime. +# GitHub-CI Status + +[comment]: <> (The following lines are generated by "scripts/generate_badges.d" that you can run online https://run.dlang.io/) + +| Os | amd64 | AArch64 | ARM | MIPS | +| :-- | --: | --: | --: | --: | +| FreeBSD | [![][i1a0]][l1a0]<br/>![][d1] | ![][d0]<br/>![][d1] | ![][d0]<br/>![][d1] | ![][d0]<br/>![][d1] | +| Linux | [![][i2a0]][l2a0]<br/>[![][i2a1]][l2a1] | [![][i2b0]][l2b0]<br/>![][d1] | [![][i2c0]][l2c0]<br/>![][d1] | [![][i2d0]][l2d0]<br/>![][d1] | +| MacOS | [![][i3a0]][l3a0]<br/>![][d1] | ![][d0]<br/>![][d1] | ![][d0]<br/>![][d1] | ![][d0]<br/>![][d1] | +| Windows | [![][i4a0]][l4a0]<br/>![][d1] | ![][d0]<br/>![][d1] | ![][d0]<br/>![][d1] | ![][d0]<br/>![][d1] | + +[d0]: https://img.shields.io/badge/CMake-N%2FA-lightgrey +[d1]: https://img.shields.io/badge/Bazel-N%2FA-lightgrey +[i1a0]: https://img.shields.io/github/workflow/status/google/cpu_features/amd64%20FreeBSD%20CMake/main?label=CMake +[i2a0]: https://img.shields.io/github/workflow/status/google/cpu_features/amd64%20Linux%20CMake/main?label=CMake +[i2a1]: https://img.shields.io/github/workflow/status/google/cpu_features/amd64%20Linux%20Bazel/main?label=Bazel +[i2b0]: https://img.shields.io/github/workflow/status/google/cpu_features/AArch64%20Linux%20CMake/main?label=CMake +[i2c0]: https://img.shields.io/github/workflow/status/google/cpu_features/ARM%20Linux%20CMake/main?label=CMake +[i2d0]: https://img.shields.io/github/workflow/status/google/cpu_features/MIPS%20Linux%20CMake/main?label=CMake +[i3a0]: https://img.shields.io/github/workflow/status/google/cpu_features/amd64%20MacOS%20CMake/main?label=CMake +[i4a0]: https://img.shields.io/github/workflow/status/google/cpu_features/amd64%20Windows%20CMake/main?label=CMake +[l1a0]: https://github.com/google/cpu_features/actions/workflows/amd64_freebsd_cmake.yml +[l2a0]: https://github.com/google/cpu_features/actions/workflows/amd64_linux_cmake.yml +[l2a1]: https://github.com/google/cpu_features/actions/workflows/amd64_linux_bazel.yml +[l2b0]: https://github.com/google/cpu_features/actions/workflows/aarch64_linux_cmake.yml +[l2c0]: https://github.com/google/cpu_features/actions/workflows/arm_linux_cmake.yml +[l2d0]: https://github.com/google/cpu_features/actions/workflows/mips_linux_cmake.yml +[l3a0]: https://github.com/google/cpu_features/actions/workflows/amd64_macos_cmake.yml +[l4a0]: https://github.com/google/cpu_features/actions/workflows/amd64_windows_cmake.yml + ## Table of Contents - [Design Rationale](#rationale) diff --git a/bazel/ci/README.md b/bazel/ci/README.md new file mode 100644 index 0000000..c5fcde9 --- /dev/null +++ b/bazel/ci/README.md @@ -0,0 +1,5 @@ +## Usage +To build tests with bazel +```sh +bazel test -s --verbose_failures //... +``` diff --git a/cmake/ci/README.md b/cmake/ci/README.md index b6e6628..0d898d8 100644 --- a/cmake/ci/README.md +++ b/cmake/ci/README.md @@ -1,27 +1,3 @@ -# GitHub-CI Status -| Os | amd64 | AArch64 | ARM | MIPS | -| :-- | --: | --: | --: | --: | -| FreeBSD | [![][img_1a]][lnk_1a] | ![][img_na] | ![][img_na] | ![][img_na] | -| Linux | [![][img_2a]][lnk_2a] | [![][img_2b]][lnk_2b] | [![][img_2c]][lnk_2c] | [![][img_2d]][lnk_2d] | -| MacOS | [![][img_3a]][lnk_3a] | ![][img_na] | ![][img_na] | ![][img_na] | -| Windows | [![][img_4a]][lnk_4a] | ![][img_na] | ![][img_na] | ![][img_na] | - -[img_na]: https://img.shields.io/badge/build-N%2FA-lightgrey -[lnk_1a]: https://github.com/google/cpu_features/actions/workflows/amd64_freebsd_cmake.yml -[img_1a]: https://img.shields.io/github/workflow/status/google/cpu_features/amd64%20FreeBSD%20CMake/main -[lnk_2a]: https://github.com/google/cpu_features/actions/workflows/amd64_linux_cmake.yml -[img_2a]: https://img.shields.io/github/workflow/status/google/cpu_features/amd64%20Linux%20CMake/main -[lnk_3a]: https://github.com/google/cpu_features/actions/workflows/amd64_macos_cmake.yml -[img_3a]: https://img.shields.io/github/workflow/status/google/cpu_features/amd64%20MacOS%20CMake/main -[lnk_4a]: https://github.com/google/cpu_features/actions/workflows/amd64_windows_cmake.yml -[img_4a]: https://img.shields.io/github/workflow/status/google/cpu_features/amd64%20Windows%20CMake/main -[lnk_2b]: https://github.com/google/cpu_features/actions/workflows/aarch64_linux_cmake.yml -[img_2b]: https://img.shields.io/github/workflow/status/google/cpu_features/AArch64%20Linux%20CMake/main -[lnk_2c]: https://github.com/google/cpu_features/actions/workflows/arm_linux_cmake.yml -[img_2c]: https://img.shields.io/github/workflow/status/google/cpu_features/ARM%20Linux%20CMake/main -[lnk_2d]: https://github.com/google/cpu_features/actions/workflows/mips_linux_cmake.yml -[img_2d]: https://img.shields.io/github/workflow/status/google/cpu_features/MIPS%20Linux%20CMake/main - ## Makefile/Docker testing To test the build on various distro, we are using docker containers and a Makefile for orchestration. @@ -42,7 +18,7 @@ make note: you can also use from top directory ```sh -make --directory=ci +make --directory=cmake/ci ``` ### Example diff --git a/scripts/generate_badges.d b/scripts/generate_badges.d index 8eee1fd..6dd726b 100644 --- a/scripts/generate_badges.d +++ b/scripts/generate_badges.d @@ -1,4 +1,4 @@ -import std.algorithm : each, map, cartesianProduct, filter; +import std.algorithm : each, map, cartesianProduct, filter, joiner, sort, uniq; import std.array : array; import std.conv : to; import std.format; @@ -6,6 +6,12 @@ import std.range : chain, only; import std.stdio; import std.traits : EnumMembers; +enum BuildSystem +{ + CMake, + Bazel +} + enum Cpu { amd64, @@ -22,46 +28,73 @@ enum Os Windows } -struct Configuration +struct Badge { const: + Cpu cpu; Os os; + BuildSystem build_system; - bool disabled() + string id() { - import std.algorithm.comparison : among; - - return os.among(Os.FreeBSD, Os.Windows, Os.MacOS) && cpu.among(Cpu.AArch64, Cpu.ARM, Cpu - .MIPS); + return format("%d%c%d", cast(uint)(os) + 1, cast(char)('a' + cpu), cast(uint)(build_system)); } - string cell() + string disabled_image_ref() { - return format("%d%c", cast(uint)(os) + 1, cast(char)('a' + cpu)); + return format("[d%d]", cast(uint)(build_system)); } string link_ref() { - return format("[lnk_%s]", cell()); + return format("[l%s]", id()); } string image_ref() { - return format("[img_%s]", cell()); + return format("[i%s]", id()); } - string cell_text() + bool enabled() { - if (disabled()) - return "![][img_na]"; - return format("[![]%s]%s", image_ref, link_ref); + final switch (build_system) + { + case BuildSystem.CMake: + return os == Os.Linux || cpu == Cpu.amd64; + case BuildSystem.Bazel: + return os == Os.Linux && cpu == Cpu.amd64; + } } -} + string text() + { + if (enabled()) + return format("[![]%s]%s", image_ref, link_ref); + return format("![]%s", disabled_image_ref); + } + + string disabled_image_link() + { + return format("%s: https://img.shields.io/badge/%s-N%%2FA-lightgrey", disabled_image_ref, build_system); + } -immutable allCpus = [EnumMembers!Cpu]; -immutable allOses = [EnumMembers!Os]; + string link_decl() + { + import std.uni : toLower; + + const filename = toLower(format("%s_%s_%s.yml", cpu, os, build_system)); + return format("%s: https://github.com/google/cpu_features/actions/workflows/%s", link_ref, filename); + } + + string image_decl() + { + import std.uri : encode; + + const worflow_name = encode(format("%s %s %s", cpu, os, build_system)); + return format("%s: https://img.shields.io/github/workflow/status/google/cpu_features/%s/main?label=%s", image_ref, worflow_name, build_system); + } +} auto tableHeader(in Cpu[] cpus) { @@ -73,40 +106,55 @@ auto tableAlignment(in Cpu[] cpus) return chain(only(":--"), cpus.map!(v => "--:")).array; } -auto tableRow(in Os os, in Cpu[] cpus) +auto tableCell(Range)(in Os os, in Cpu cpu, Range badges) { - return chain(only(os.to!string), cpus.map!(cpu => Configuration(cpu, os).cell_text())).array; + return badges + .filter!(b => b.cpu == cpu && b.os == os) + .map!(b => b.text()) + .joiner("<br/>") + .to!string; } -auto tableRows(in Os[] oses, in Cpu[] cpus) +auto tableRow(Range)(in Os os, in Cpu[] cpus, Range badges) { - return oses.map!(os => tableRow(os, cpus)).array; + return chain(only(os.to!string), cpus.map!(cpu => tableCell(os, cpu, badges))).array; } -auto table(in Os[] oses, in Cpu[] cpus) +auto tableRows(Range)(in Os[] oses, in Cpu[] cpus, Range badges) { - return chain(only(tableHeader(cpus)), only(tableAlignment(cpus)), tableRows(oses, cpus)); + return oses.map!(os => tableRow(os, cpus, badges)).array; +} + +auto table(Range)(in Os[] oses, in Cpu[] cpus, Range badges) +{ + return chain(only(tableHeader(cpus)), only(tableAlignment(cpus)), tableRows(oses, cpus, badges)); } void main() { immutable allCpus = [EnumMembers!Cpu]; immutable allOses = [EnumMembers!Os]; + immutable allBuildSystems = [EnumMembers!BuildSystem]; + + auto badges = cartesianProduct(allCpus, allOses, allBuildSystems).map!( + t => Badge(t[0], t[1], t[2])); - writefln("%(|%-( %-21s |%) |\n%) |", table(allOses, allCpus)); + writefln("%(|%-( %s |%) |\n%) |", table(allOses, allCpus, badges)); writeln(); - writeln("[img_na]: https://img.shields.io/badge/build-N%2FA-lightgrey"); - cartesianProduct(allCpus, allOses) - .map!(t => Configuration(t[0], t[1])) - .filter!(conf => !conf.disabled) - .each!((conf) { - import std.uni : toLower; - import std.uri : encode; - - const filename = toLower(format("%s_%s_%s.yml", conf.cpu, conf.os, "cmake")); - writefln("%s: https://github.com/google/cpu_features/actions/workflows/%s", conf.link_ref, filename); - - const worflow_name = encode(format("%s %s %s", conf.cpu, conf.os, "CMake")); - writefln("%s: https://img.shields.io/github/workflow/status/google/cpu_features/%s/main", conf.image_ref, worflow_name); - }); + badges + .filter!(b => !b.enabled) + .map!(b => b.disabled_image_link()) + .array + .sort + .uniq + .each!writeln; + + badges + .filter!(b => b.enabled) + .map!(b => [b.link_decl(), b.image_decl()]) + .joiner() + .array + .sort + .uniq + .each!writeln; } |