From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: ChengyuZhu6 <hudson@cyzhu.com>, linux-erofs@lists.ozlabs.org
Cc: Chengyu Zhu <hudsonzhu@tencent.com>
Subject: Re: [PATCH v1] erofs-utils: lib: oci: support auto-detecting host platform
Date: Mon, 12 Jan 2026 11:10:02 +0800 [thread overview]
Message-ID: <4808564e-e69d-4509-8c04-e1810eef0f90@linux.alibaba.com> (raw)
In-Reply-To: <20260110082732.61528-1-hudson@cyzhu.com>
Hi Chengyu,
On 2026/1/10 16:27, ChengyuZhu6 wrote:
> From: Chengyu Zhu <hudsonzhu@tencent.com>
>
> Currently, the platform is hard-coded to "linux/amd64" if not specified.
> This patch introduces `ocierofs_get_platform_spec` helper to detect the
> host platform (OS and architecture) at compile time.
>
> Signed-off-by: Chengyu Zhu <hudsonzhu@tencent.com>
> ---
> lib/remotes/oci.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 44 insertions(+), 2 deletions(-)
>
> diff --git a/lib/remotes/oci.c b/lib/remotes/oci.c
> index c8711ea..911abd5 100644
> --- a/lib/remotes/oci.c
> +++ b/lib/remotes/oci.c
> @@ -1089,13 +1089,55 @@ static int ocierofs_parse_ref(struct ocierofs_ctx *ctx, const char *ref_str)
> return 0;
> }
>
> +static char *ocierofs_get_platform_spec(void)
> +{
> +#if defined(__linux__)
> + const char *os = "linux";
> +#elif defined(__APPLE__)
> + const char *os = "darwin";
> +#elif defined(_WIN32)
> + const char *os = "windows";
> +#elif defined(__FreeBSD__)
> + const char *os = "freebsd";
> +#else
Is there an unknown os annotation or we should just error out?
> + const char *os = "linux";
> +#endif
I think it would be better to rearrange it as:
const char *os, *platform;
#if defined(__linux__)
os = "linux";
#elif defined(__APPLE__)
os = "darwin"
#elif ...
#else
return -EOPNOTSUPP;
#endif
> +
> +#if defined(__x86_64__) || defined(__amd64__)
> + const char *arch = "amd64";
> +#elif defined(__aarch64__) || defined(__arm64__)
> + const char *arch = "arm64";
> +#elif defined(__i386__)
> + const char *arch = "386";
> +#elif defined(__arm__)
> + const char *arch = "arm";
> +#elif defined(__riscv) && (__riscv_xlen == 64)
> + const char *arch = "riscv64";
> +#elif defined(__ppc64__)
> +#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
> + const char *arch = "ppc64le";
> +#else
> + const char *arch = "ppc64";
> +#endif
> +#elif defined(__s390x__)
> + const char *arch = "s390x";
> +#else
> + const char *arch = "amd64";
Same here and
Is there an unknown platform annotation or we should just error out?
Thanks,
Gao Xiang
next prev parent reply other threads:[~2026-01-12 3:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-10 8:27 [PATCH v1] erofs-utils: lib: oci: support auto-detecting host platform ChengyuZhu6
2026-01-12 3:10 ` Gao Xiang [this message]
2026-01-15 3:38 ` [PATCH v2] " ChengyuZhu6
2026-01-15 5:13 ` Gao Xiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4808564e-e69d-4509-8c04-e1810eef0f90@linux.alibaba.com \
--to=hsiangkao@linux.alibaba.com \
--cc=hudson@cyzhu.com \
--cc=hudsonzhu@tencent.com \
--cc=linux-erofs@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox