Skip to content

Commit 5fc8ca6

Browse files
zeroshadeamoeba
andauthored
fix(c/driver_manager,rust/driver_manager): establish standard platform tuples (#3313)
Add to the docs an authoritative definition of the platform tuples we'll use for the driver manager (for OS, Arch, env). Update the C and Rust driver managers to use these authoritative platform tuple strings. This should unify everything to a specific way of identifying platform tuples with Driver manifests. --------- Co-authored-by: Bryce Mecum <petridish@gmail.com>
1 parent 86cba9a commit 5fc8ca6

File tree

4 files changed

+197
-8
lines changed

4 files changed

+197
-8
lines changed

c/driver_manager/current_arch.h

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,38 @@
1919

2020
#include <string>
2121

22+
#if defined(_WIN32)
23+
#define ADBC_LITTLE_ENDIAN 1
24+
#else
25+
#if defined(__APPLE__) || defined(__FreeBSD__)
26+
#include <machine/endian.h>
27+
#elif defined(sun) || defined(__sun)
28+
#include <sys/byteorder.h>
29+
#elif !defined(_AIX)
30+
#include <endian.h>
31+
#endif
32+
#if !defined(__BYTE_ORDER__) || !defined(__ORDER_LITTLE_ENDIAN__)
33+
#define ADBC_LITTLE_ENDIAN 1
34+
#else
35+
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
36+
#define ADBC_LITTLE_ENDIAN 1
37+
#else
38+
#define ADBC_LITTLE_ENDIAN 0
39+
#endif
40+
#endif
41+
#endif
42+
2243
namespace adbc {
2344

2445
const std::string& CurrentArch() {
2546
#if defined(_WIN32)
2647
static const std::string platform = "windows";
2748
#elif defined(__APPLE__)
28-
static const std::string platform = "osx";
49+
static const std::string platform = "macos";
2950
#elif defined(__FreeBSD__)
3051
static const std::string platform = "freebsd";
52+
#elif defined(__OpenBSD__)
53+
static const std::string platform = "openbsd";
3154
#elif defined(__linux__)
3255
static const std::string platform = "linux";
3356
#else
@@ -37,17 +60,45 @@ const std::string& CurrentArch() {
3760
#if defined(__x86_64__) || defined(__amd64__) || defined(_M_X64) || defined(_M_AMD64)
3861
static const std::string arch = "amd64";
3962
#elif defined(__aarch64__) || defined(_M_ARM64) || defined(__ARM_ARCH_ISA_A64)
63+
#ifdef ADBC_LITTLE_ENDIAN
4064
static const std::string arch = "arm64";
65+
#else
66+
static const std::string arch = "arm64be";
67+
#endif
4168
#elif defined(__i386__) || defined(_M_IX86) || defined(_M_X86)
4269
static const std::string arch = "x86";
4370
#elif defined(__arm__) || defined(_M_ARM)
71+
#ifdef ADBC_LITTLE_ENDIAN
4472
static const std::string arch = "arm";
73+
#else
74+
static const std::string arch = "armbe";
75+
#endif
4576
#elif defined(__riscv) || defined(_M_RISCV)
77+
#if defined(__riscv_xlen) && __riscv_xlen == 64
78+
static const std::string arch = "riscv64";
79+
#else
4680
static const std::string arch = "riscv";
81+
#endif
82+
#elif defined(__ppc64__) || defined(__powerpc64__)
83+
#ifdef ADBC_LITTLE_ENDIAN
84+
static const std::string arch = "powerpc64le";
85+
#else
86+
static const std::string arch = "powerpc64";
87+
#endif
4788
#elif defined(__powerpc__) || defined(__ppc__) || defined(_M_PPC)
4889
static const std::string arch = "powerpc";
4990
#elif defined(__s390x__) || defined(_M_S390)
5091
static const std::string arch = "s390x";
92+
#elif defined(__sparc__) || defined(__sparc)
93+
#if defined(_LP64) || defined(__LP64__)
94+
static const std::string arch = "sparc64";
95+
#else
96+
static const std::string arch = "sparc";
97+
#endif
98+
#elif defined(__wasm32__)
99+
static const std::string arch = "wasm32";
100+
#elif defined(__wasm64__)
101+
static const std::string arch = "wasm64";
51102
#else
52103
static const std::string arch = "unknown";
53104
#endif

docs/source/format/driver_manifests.rst

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,83 @@ a string (single path) or a table of platform-specific paths. The ``Driver.shar
239239
needed to successfully load a driver manifest. The other keys are optional, but provide useful metadata
240240
about the driver.
241241

242+
Platform Tuples
243+
^^^^^^^^^^^^^^^
244+
245+
Since the manifests use platform tuples to specify the different systems that
246+
drivers might be built for, it is important to create a consistent way to name
247+
these tuples. Specifically, consistent naming for operating system (OS) and
248+
architecture combinations that can be used by all systems that read and/or write
249+
manifest files.
250+
251+
As such, the following table should be considered the authoritative list:
252+
253+
+---------------+---------------+
254+
| OS | Tuple Name |
255+
+===============+===============+
256+
| Linux | ``linux`` |
257+
+---------------+---------------+
258+
| macOS | ``macos`` |
259+
+---------------+---------------+
260+
| Windows | ``windows`` |
261+
+---------------+---------------+
262+
| FreeBSD | ``freebsd`` |
263+
+---------------+---------------+
264+
| OpenBSD | ``openbsd`` |
265+
+---------------+---------------+
266+
267+
+---------------+-----------------+
268+
| Architecture | Tuple Name |
269+
+===============+=================+
270+
| i386 | ``x86`` |
271+
+---------------+-----------------+
272+
| x86 | ``x86`` |
273+
+---------------+-----------------+
274+
| x86-64 | ``amd64`` |
275+
+---------------+-----------------+
276+
| x64 | ``amd64`` |
277+
+---------------+-----------------+
278+
| amd64 | ``amd64`` |
279+
+---------------+-----------------+
280+
| arm (32-bit) | ``arm`` |
281+
+---------------+-----------------+
282+
| armbe (32-bit)| ``armbe`` |
283+
+---------------+-----------------+
284+
| arm64be | ``arm64be`` |
285+
+---------------+-----------------+
286+
| aarch64 | ``arm64`` |
287+
+---------------+-----------------+
288+
| arm64 | ``arm64`` |
289+
+---------------+-----------------+
290+
| s390x | ``s390x`` |
291+
+---------------+-----------------+
292+
| ppc | ``powerpc`` |
293+
+---------------+-----------------+
294+
| ppc64 | ``powerpc64`` |
295+
+---------------+-----------------+
296+
| ppc64le | ``powerpc64le`` |
297+
+---------------+-----------------+
298+
| riscv | ``riscv`` |
299+
+---------------+-----------------+
300+
| riscv64 | ``riscv64`` |
301+
+---------------+-----------------+
302+
| sparc | ``sparc`` |
303+
+---------------+-----------------+
304+
| sparc64 | ``sparc64`` |
305+
+---------------+-----------------+
306+
| Wasm (32-bit) | ``wasm32`` |
307+
+---------------+-----------------+
308+
| Wasm (64-bit) | ``wasm64`` |
309+
+---------------+-----------------+
310+
311+
The construction of the platform tuple is: ``<OS>_<Architecture>``, for example:
312+
``linux_amd64``.
313+
314+
.. note::
315+
For alternative scenarios such as using musl instead of the GNU C Library
316+
(glibc) or MinGW, the tuple should have the appropriate suffix for that
317+
environment. i.e. ``linux_amd64_musl`` or ``windows_amd64_mingw``.
318+
242319
Manifest Location and Discovery
243320
-------------------------------
244321

go/adbc/drivermgr/current_arch.h

Lines changed: 53 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/driver_manager/src/lib.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,14 +1804,24 @@ fn get_search_paths(lvls: LoadFlags) -> Vec<PathBuf> {
18041804
const fn arch_triplet() -> (&'static str, &'static str, &'static str) {
18051805
#[cfg(target_arch = "x86_64")]
18061806
const ARCH: &str = "amd64";
1807-
#[cfg(target_arch = "aarch64")]
1807+
#[cfg(all(target_arch = "aarch64", target_endian = "big"))]
1808+
const ARCH: &str = "arm64be";
1809+
#[cfg(all(target_arch = "aarch64", target_endian = "little"))]
18081810
const ARCH: &str = "arm64";
1809-
#[cfg(not(any(target_arch = "x86_64", target_arch = "aarch64")))]
1811+
#[cfg(all(target_arch = "powerpc64", target_endian = "little"))]
1812+
const ARCH: &str = "powerpc64le";
1813+
#[cfg(all(target_arch = "powerpc64", target_endian = "big"))]
1814+
const ARCH: &str = "powerpc64";
1815+
#[cfg(target_arch = "riscv32")]
1816+
const ARCH: &str = "riscv";
1817+
#[cfg(not(any(
1818+
target_arch = "x86_64",
1819+
target_arch = "aarch64",
1820+
target_arch = "powerpc64",
1821+
target_arch = "riscv32",
1822+
)))]
18101823
const ARCH: &str = std::env::consts::ARCH;
18111824

1812-
#[cfg(target_os = "macos")]
1813-
const OS: &str = "osx";
1814-
#[cfg(not(target_os = "macos"))]
18151825
const OS: &str = std::env::consts::OS;
18161826

18171827
#[cfg(target_env = "musl")]

0 commit comments

Comments
 (0)