mirror of
https://github.com/google/cpu_features.git
synced 2025-07-01 13:21:13 +02:00
Add bazel ci README, update main README (#235)
This commit is contained in:

committed by
GitHub

parent
c219c921c5
commit
188d0d3c38
40
README.md
40
README.md
@ -1,18 +1,38 @@
|
|||||||
# cpu_features
|
# 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
|
A cross-platform C library to retrieve CPU features (such as available
|
||||||
instructions) at runtime.
|
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
|
## Table of Contents
|
||||||
|
|
||||||
- [Design Rationale](#rationale)
|
- [Design Rationale](#rationale)
|
||||||
|
5
bazel/ci/README.md
Normal file
5
bazel/ci/README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
## Usage
|
||||||
|
To build tests with bazel
|
||||||
|
```sh
|
||||||
|
bazel test -s --verbose_failures //...
|
||||||
|
```
|
@ -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
|
## Makefile/Docker testing
|
||||||
To test the build on various distro, we are using docker containers and a Makefile for orchestration.
|
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
|
note: you can also use from top directory
|
||||||
```sh
|
```sh
|
||||||
make --directory=ci
|
make --directory=cmake/ci
|
||||||
```
|
```
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
@ -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.array : array;
|
||||||
import std.conv : to;
|
import std.conv : to;
|
||||||
import std.format;
|
import std.format;
|
||||||
@ -6,6 +6,12 @@ import std.range : chain, only;
|
|||||||
import std.stdio;
|
import std.stdio;
|
||||||
import std.traits : EnumMembers;
|
import std.traits : EnumMembers;
|
||||||
|
|
||||||
|
enum BuildSystem
|
||||||
|
{
|
||||||
|
CMake,
|
||||||
|
Bazel
|
||||||
|
}
|
||||||
|
|
||||||
enum Cpu
|
enum Cpu
|
||||||
{
|
{
|
||||||
amd64,
|
amd64,
|
||||||
@ -22,46 +28,73 @@ enum Os
|
|||||||
Windows
|
Windows
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Configuration
|
struct Badge
|
||||||
{
|
{
|
||||||
const:
|
const:
|
||||||
|
|
||||||
Cpu cpu;
|
Cpu cpu;
|
||||||
Os os;
|
Os os;
|
||||||
|
BuildSystem build_system;
|
||||||
|
|
||||||
bool disabled()
|
string id()
|
||||||
{
|
{
|
||||||
import std.algorithm.comparison : among;
|
return format("%d%c%d", cast(uint)(os) + 1, cast(char)('a' + cpu), cast(uint)(build_system));
|
||||||
|
|
||||||
return os.among(Os.FreeBSD, Os.Windows, Os.MacOS) && cpu.among(Cpu.AArch64, Cpu.ARM, Cpu
|
|
||||||
.MIPS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
string link_ref()
|
||||||
{
|
{
|
||||||
return format("[lnk_%s]", cell());
|
return format("[l%s]", id());
|
||||||
}
|
}
|
||||||
|
|
||||||
string image_ref()
|
string image_ref()
|
||||||
{
|
{
|
||||||
return format("[img_%s]", cell());
|
return format("[i%s]", id());
|
||||||
}
|
}
|
||||||
|
|
||||||
string cell_text()
|
bool enabled()
|
||||||
{
|
{
|
||||||
if (disabled())
|
final switch (build_system)
|
||||||
return "![][img_na]";
|
{
|
||||||
return format("[![]%s]%s", image_ref, link_ref);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
immutable allCpus = [EnumMembers!Cpu];
|
string disabled_image_link()
|
||||||
immutable allOses = [EnumMembers!Os];
|
{
|
||||||
|
return format("%s: https://img.shields.io/badge/%s-N%%2FA-lightgrey", disabled_image_ref, build_system);
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
auto tableHeader(in Cpu[] cpus)
|
||||||
{
|
{
|
||||||
@ -73,40 +106,55 @@ auto tableAlignment(in Cpu[] cpus)
|
|||||||
return chain(only(":--"), cpus.map!(v => "--:")).array;
|
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()
|
void main()
|
||||||
{
|
{
|
||||||
immutable allCpus = [EnumMembers!Cpu];
|
immutable allCpus = [EnumMembers!Cpu];
|
||||||
immutable allOses = [EnumMembers!Os];
|
immutable allOses = [EnumMembers!Os];
|
||||||
|
immutable allBuildSystems = [EnumMembers!BuildSystem];
|
||||||
|
|
||||||
writefln("%(|%-( %-21s |%) |\n%) |", table(allOses, allCpus));
|
auto badges = cartesianProduct(allCpus, allOses, allBuildSystems).map!(
|
||||||
|
t => Badge(t[0], t[1], t[2]));
|
||||||
|
|
||||||
|
writefln("%(|%-( %s |%) |\n%) |", table(allOses, allCpus, badges));
|
||||||
writeln();
|
writeln();
|
||||||
writeln("[img_na]: https://img.shields.io/badge/build-N%2FA-lightgrey");
|
badges
|
||||||
cartesianProduct(allCpus, allOses)
|
.filter!(b => !b.enabled)
|
||||||
.map!(t => Configuration(t[0], t[1]))
|
.map!(b => b.disabled_image_link())
|
||||||
.filter!(conf => !conf.disabled)
|
.array
|
||||||
.each!((conf) {
|
.sort
|
||||||
import std.uni : toLower;
|
.uniq
|
||||||
import std.uri : encode;
|
.each!writeln;
|
||||||
|
|
||||||
const filename = toLower(format("%s_%s_%s.yml", conf.cpu, conf.os, "cmake"));
|
badges
|
||||||
writefln("%s: https://github.com/google/cpu_features/actions/workflows/%s", conf.link_ref, filename);
|
.filter!(b => b.enabled)
|
||||||
|
.map!(b => [b.link_decl(), b.image_decl()])
|
||||||
const worflow_name = encode(format("%s %s %s", conf.cpu, conf.os, "CMake"));
|
.joiner()
|
||||||
writefln("%s: https://img.shields.io/github/workflow/status/google/cpu_features/%s/main", conf.image_ref, worflow_name);
|
.array
|
||||||
});
|
.sort
|
||||||
|
.uniq
|
||||||
|
.each!writeln;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user