OS vs. environment version
the distinction came from LLVM Triple, it is why I included it in the document (I assume LLVM knows better than me such things
).
The OS version is lot more common than environment version.
Let take two examples for seeing the differences:
-
x86_64-unknown-openbsd6.1 : â6.1â is the version of the OS âopenbsdâ. there are no environment and no environment version (just empties).
-
i686-unknown-linux-musl : here for Linux, there is no OS version. But an environment exists: âmuslâ (it is an alternative libc library different than glibc). The environment version is also empty. But if musl decides to do breaking change some hypotetical day, it would be possible to target it with environment version.
From LLVM Triple specification, the format is ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT. With OPERATING_SYSTEM and ENVIRONMENT that could contains a version number âMAJORâ or âMAJOR.MINORâ or âMAJOR.MINOR.MICROâ.
Triple parsing
In fact, I didnât intent to parse the LLVM triple: librustc_back doesnât require it. But if parsing would be required, I think I would rely on LLVM code.
Currently, the target passed to rustc is statically compared to the list of buildins target, and once a target string matches, it returns a Target struct already parsed.
Here for OpenBSD 6.1 on i686, a Target with target_os_version and target_env_version:
Target {
llvm_target: "i686-unknown-openbsd6.1".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(),
arch: "x86".to_string(),
target_os: "openbsd".to_string(),
target_os_version: "6.1".to_string(),
target_env: "".to_string(),
target_env_version: "".to_string(),
target_vendor: "unknown".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: base,
}
For the problem of dealing with breaking changes, having target_os_version (and target_env_version) defined as attribute (for conditional compilation) in enough.
But having to add in librustc_back new targets at every release (and for every architecture of the OS) could be problematic. Here I dunno about the right way. Having a kind of âtemplateâ and parsing the triple could help.
Version comparison
I agree that operators would hides some magic. But to be usable as attributes (and so in conditional compilation), target_os_version and target_env_version had to be string (if I correcly understood this part â please correct me if I am wrong).
An alternative to the âmagicâ would be having specific predicates like version_lt(), version_le(), version_gt(), and version_ge().