Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate README.md supported targets with CI #686

Closed
Emilgardis opened this issue Apr 7, 2022 · 3 comments · Fixed by #753
Closed

Validate README.md supported targets with CI #686

Emilgardis opened this issue Apr 7, 2022 · 3 comments · Fixed by #753

Comments

@Emilgardis
Copy link
Member

We should investigate if it would be possible to validate that the supported target table is correct

https://github.com/cross-rs/cross#supported-targets

Alexhuszagh added a commit to Alexhuszagh/cross that referenced this issue May 26, 2022
Attempts to recreate the table present in README.md, with an initial
script to generate the table information for a given target.

Related to cross-rs#686.
@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented May 26, 2022

I've created a very rudimentary attempt at this in target_info (only partially working on Android, and works for a few tested musl targets) to auto-generate a table similar to the one in README to compare and validate the information. This might also simplify the validation of the versions in #591.

The use of the script is quite simple (and a wrapper with many targets would be provided to extract info for all targets):

$ export TARGET=aarch64-unknown-linux-musl
$ docker run -e TARGET ghcr.io/cross-rs/"$TARGET":main bash -c "`cat extract_target_info.sh`"
| `aarch64-unknown-linux-musl`         | 1.2.0  | 9.2.0   || 5.1.0 |

How this works is it queries the version information from GCC (or Clang), detects if Qemu is present and if so, gets the Qemu version. and determines if the command provided by CXX_$target exists, and if so, says there is C++ support. For libc, it's a bit more complicated, but most libc libraries are executable (especially musl), or have version info attached to them (glibc). For glibc, we might have a library like libc-2.31.so, or glibc 2.31. For musl, we can just execute the libc (using qemu if required) and extract the version info.

This is then formatted to the desired output. This definitely should be possible for most targets, and we can do it after the image has been completed by using information provided by the toolchain.

@Emilgardis
Copy link
Member Author

Awesome!

Something I just realised, we should/could label the images with the different version

@Alexhuszagh
Copy link
Contributor

That might be easier. I can get the libc versions for everything except FreeBSD pretty easily, and FreeBSD isn't hard, but the libc reported in the README is the base release (which is quite different than the symbol libc version).

For example, for the current base release of 12.3, we would get FBSD_1.5 based on Symbol Versioning.

So for this and Android, I'm not sure what the correct output should be. For FreeBSD, is the correct libc version 12.3 or 1.5? And for Android, I'm currently reporting the LLVM version, but should I report the NDK version?

Alexhuszagh added a commit to Alexhuszagh/cross that referenced this issue Jun 3, 2022
Attempts to recreate the table present in README.md, which
can extract the target information for a single target
or for all targets.

Should currently support the following targets:
- Android
- glibc
- musl
- MinGW
- FreeBSD
- NetBSD
- newlib

Closes cross-rs#686.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this issue Jun 3, 2022
Attempts to recreate the table present in README.md, which
can extract the target information for a single target
or for all targets.

Should currently support the following targets:
- Android
- glibc
- musl
- MinGW
- FreeBSD
- NetBSD
- newlib

Closes cross-rs#686.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this issue Jun 3, 2022
Attempts to recreate the table present in README.md, which
can extract the target information for a single target
or for all targets.

Should currently support the following targets:
- Android
- glibc
- musl
- MinGW
- FreeBSD
- NetBSD
- newlib

Closes cross-rs#686.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this issue Jun 3, 2022
Attempts to recreate the table present in README.md, which
can extract the target information for a single target
or for all targets.

Should currently support the following targets:
- Android
- glibc
- musl
- MinGW
- FreeBSD
- NetBSD
- newlib

Closes cross-rs#686.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this issue Jun 3, 2022
Attempts to recreate the table present in README.md, which
can extract the target information for a single target
or for all targets.

Should currently support the following targets:
- Android
- glibc
- musl
- MinGW
- FreeBSD
- NetBSD
- newlib

Closes cross-rs#686.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this issue Jun 3, 2022
Attempts to recreate the table present in README.md, which
can extract the target information for a single target
or for all targets.

Should currently support the following targets:
- Android
- glibc
- musl
- MinGW
- FreeBSD
- NetBSD
- newlib

Closes cross-rs#686.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this issue Jun 3, 2022
Attempts to recreate the table present in README.md, which
can extract the target information for a single target
or for all targets.

Should currently support the following targets:
- Android
- glibc
- musl
- MinGW
- FreeBSD
- NetBSD
- newlib

Closes cross-rs#686.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this issue Jun 6, 2022
Attempts to recreate the table present in README.md, which
can extract the target information for a single target
or for all targets.

Should currently support the following targets:
- Android
- glibc
- musl
- MinGW
- FreeBSD
- NetBSD
- newlib

Closes cross-rs#686.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this issue Jun 6, 2022
Attempts to recreate the table present in README.md, which
can extract the target information for a single target
or for all targets.

Should currently support the following targets:
- Android
- glibc
- musl
- MinGW
- FreeBSD
- NetBSD
- newlib

Closes cross-rs#686.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this issue Jun 7, 2022
Attempts to recreate the table present in README.md, which
can extract the target information for a single target
or for all targets.

Should currently support the following targets:
- Android
- glibc
- musl
- MinGW
- FreeBSD
- NetBSD
- newlib

Closes cross-rs#686.
bors bot added a commit that referenced this issue Jun 7, 2022
753: Add scripts to validate target info. r=Emilgardis a=Alexhuszagh

Attempts to recreate the table present in README.md, which
can extract the target information for a single target
or for all targets.

Should currently support the following targets:
- Android
- glibc
- musl
- MinGW
- FreeBSD
- NetBSD
- newlib

Closes #686.

This produces the following table:

| Target                               |  libc  |   GCC   | C++ | QEMU  |
|:-:|:-:|:-:|:-:|:-:|
| `aarch64-linux-android`              | 9.0.8  | 9.0.8   | ✓   | 5.1.0 |                                                                                                                           
| `aarch64-unknown-linux-gnu`          | 2.23   | 5.4.0   | ✓   | 5.1.0 |
| `aarch64-unknown-linux-musl`         | 1.2.0  | 9.2.0   | ✓   | 5.1.0 |
| `arm-linux-androideabi`              | 9.0.8  | 9.0.8   | ✓   | 5.1.0 |
| `arm-unknown-linux-gnueabi`          | 2.23   | 5.4.0   | ✓   | 5.1.0 |
| `arm-unknown-linux-gnueabihf`        | 2.17   | 8.3.0   | ✓   | 5.1.0 |
| `arm-unknown-linux-musleabi`         | 1.2.0  | 9.2.0   | ✓   | 5.1.0 |
| `arm-unknown-linux-musleabihf`       | 1.2.0  | 9.2.0   | ✓   | 5.1.0 |
| `armv5te-unknown-linux-gnueabi`      | 2.27   | 7.5.0   | ✓   | 5.1.0 |
| `armv5te-unknown-linux-musleabi`     | 1.2.0  | 9.2.0   | ✓   | 5.1.0 |
| `armv7-linux-androideabi`            | 9.0.8  | 9.0.8   | ✓   | 5.1.0 |
| `armv7-unknown-linux-gnueabihf`      | 2.23   | 5.4.0   | ✓   | 5.1.0 |
| `armv7-unknown-linux-musleabihf`     | 1.2.0  | 9.2.0   | ✓   | 5.1.0 |
| `i586-unknown-linux-gnu`             | 2.23   | 5.4.0   | ✓   | N/A   |
| `i586-unknown-linux-musl`            | 1.2.0  | 9.2.0   | ✓   | N/A   |
| `i686-linux-android`                 | 9.0.8  | 9.0.8   | ✓   | 5.1.0 |
| `i686-pc-windows-gnu`                | N/A    | 7.5     | ✓   | N/A   |
| `i686-unknown-freebsd`               | 1.5    | 6.4.0   | ✓   | N/A   |
| `i686-unknown-linux-gnu`             | 2.23   | 5.4.0   | ✓   | 5.1.0 |
| `i686-unknown-linux-musl`            | 1.2.0  | 9.2.0   | ✓   | N/A   |
| `mips-unknown-linux-gnu`             | 2.23   | 5.4.0   | ✓   | 5.1.0 |
| `mips-unknown-linux-musl`            | 1.2.0  | 9.2.0   | ✓   | 5.1.0 |
| `mips64-unknown-linux-gnuabi64`      | 2.23   | 5.4.0   | ✓   | 5.1.0 |
| `mips64el-unknown-linux-gnuabi64`    | 2.23   | 5.4.0   | ✓   | 5.1.0 |
| `mipsel-unknown-linux-gnu`           | 2.23   | 5.4.0   | ✓   | 5.1.0 |
| `mipsel-unknown-linux-musl`          | 1.2.0  | 9.2.0   | ✓   | 5.1.0 |
| `powerpc-unknown-linux-gnu`          | 2.23   | 5.4.0   | ✓   | 5.1.0 |
| `powerpc64-unknown-linux-gnu`        | 2.23   | 5.4.0   | ✓   | 5.1.0 |
| `powerpc64le-unknown-linux-gnu`      | 2.23   | 5.4.0   | ✓   | N/A   |
| `riscv64gc-unknown-linux-gnu`        | 2.27   | 7.5.0   | ✓   | 5.1.0 |
| `s390x-unknown-linux-gnu`            | 2.23   | 5.4.0   | ✓   | 5.1.0 |
| `sparc64-unknown-linux-gnu`          | 2.23   | 5.4.0   | ✓   | 5.1.0 |
| `thumbv6m-none-eabi`                 | 2.2.0  | 4.9.3   |     | N/A   |
| `thumbv7em-none-eabi`                | 2.2.0  | 4.9.3   |     | N/A   |
| `thumbv7em-none-eabihf`              | 2.2.0  | 4.9.3   |     | N/A   |
| `thumbv7m-none-eabi`                 | 2.2.0  | 4.9.3   |     | N/A   |
| `x86_64-linux-android`               | 9.0.8  | 9.0.8   | ✓   | 5.1.0 |
| `x86_64-pc-windows-gnu`              | N/A    | 7.3     | ✓   | N/A   |
| `x86_64-unknown-freebsd`             | 1.5    | 6.4.0   | ✓   | N/A   |
| `x86_64-unknown-linux-gnu`           | 2.17   | 4.8.5   | ✓   | 4.2.1 |
| `x86_64-unknown-linux-musl`          | 1.2.0  | 9.2.0   | ✓   | N/A   |
| `x86_64-unknown-netbsd`              | 9.2.0  | 9.4.0   | ✓   | N/A   |

There's a few mild differences here, but I think they're correct:
- FreeBSD uses the [symbol versioning](https://wiki.freebsd.org/SymbolVersioning) for libc.
- Android libc uses the LLVM version, and the compiler version isn't the native GCC toolchain either.

A few notes on how this works:
- C++ support is checked by there being a C++ executable, and it can compile a simple program (see below):
- Compiler version is detected by the output of GCC or Clang by a regular expression.
- Qemu version is detected by the presence of a Qemu binary and extracted via a regular expression.
- libc verson is quite intricate, but interesting:
  - If Android, the libc version is just the compiler version (Clang == LLVM).
  - If musl, we execute the binary and extract the version via a regular expression.
  - If glibc, we use the versioned filenames to get the version (`libc-2.17.so`).
  - If newlib, we use `dpkg` to get the package version which has the newlib version.
  - For FreeBSD, we wrote the FreeBSD version to file, and then match that to the libc version.
  - For NetBSD, we can read the version from the `libc.so` symbols, grepped for `NetBSD`.
  - For Windows, intentional passthrough.

**C++ Program**

This may fail in the case we cannot compile a C program to begin with (AKA, newlib, which we have missing startfiles, etc.). This really doesn't matter right now, since none of these bare-metal targets support C++, although in the future we may want to add `-nostartfiles` during compilation.

```cpp
#include <iostream>
int main() {
    std::cout << "Testing this" << std::endl;
}
```

Co-authored-by: Alex Huszagh <[email protected]>
@bors bors bot closed this as completed in e45ddaf Jun 7, 2022
Emilgardis pushed a commit to Emilgardis/cross that referenced this issue Jun 7, 2022
Attempts to recreate the table present in README.md, which
can extract the target information for a single target
or for all targets.

Should currently support the following targets:
- Android
- glibc
- musl
- MinGW
- FreeBSD
- NetBSD
- newlib

Closes cross-rs#686.
Emilgardis pushed a commit to Emilgardis/cross that referenced this issue Jun 7, 2022
Attempts to recreate the table present in README.md, which
can extract the target information for a single target
or for all targets.

Should currently support the following targets:
- Android
- glibc
- musl
- MinGW
- FreeBSD
- NetBSD
- newlib

Closes cross-rs#686.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants