All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] erofs-utils: lib: oci: support auto-detecting host platform
@ 2026-01-10  8:27 ChengyuZhu6
  2026-01-12  3:10 ` Gao Xiang
  2026-01-15  3:38 ` [PATCH v2] " ChengyuZhu6
  0 siblings, 2 replies; 4+ messages in thread
From: ChengyuZhu6 @ 2026-01-10  8:27 UTC (permalink / raw)
  To: linux-erofs; +Cc: hsiangkao, Chengyu Zhu

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
+	const char *os = "linux";
+#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";
+#endif
+	char *platform;
+
+	if (asprintf(&platform, "%s/%s", os, arch) < 0)
+		return NULL;
+	return platform;
+}
+
 /**
  * ocierofs_init - Initialize OCI context
  * @ctx: OCI context structure to initialize
  * @config: OCI configuration
  *
  * Initialize OCI context structure, set up CURL handle, and configure
- * default parameters including platform (linux/amd64), registry
+ * default parameters including platform (host platform), registry
  * (registry-1.docker.io), and tag (latest).
  *
  * Return: 0 on success, negative errno on failure
@@ -1120,7 +1162,7 @@ static int ocierofs_init(struct ocierofs_ctx *ctx, const struct ocierofs_config
 	if (config->platform)
 		ctx->platform = strdup(config->platform);
 	else
-		ctx->platform = strdup("linux/amd64");
+		ctx->platform = ocierofs_get_platform_spec();
 	if (!ctx->registry || !ctx->tag || !ctx->platform)
 		return -ENOMEM;
 
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] erofs-utils: lib: oci: support auto-detecting host platform
  2026-01-10  8:27 [PATCH v1] erofs-utils: lib: oci: support auto-detecting host platform ChengyuZhu6
@ 2026-01-12  3:10 ` Gao Xiang
  2026-01-15  3:38 ` [PATCH v2] " ChengyuZhu6
  1 sibling, 0 replies; 4+ messages in thread
From: Gao Xiang @ 2026-01-12  3:10 UTC (permalink / raw)
  To: ChengyuZhu6, linux-erofs; +Cc: Chengyu Zhu

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] erofs-utils: lib: oci: support auto-detecting host platform
  2026-01-10  8:27 [PATCH v1] erofs-utils: lib: oci: support auto-detecting host platform ChengyuZhu6
  2026-01-12  3:10 ` Gao Xiang
@ 2026-01-15  3:38 ` ChengyuZhu6
  2026-01-15  5:13   ` Gao Xiang
  1 sibling, 1 reply; 4+ messages in thread
From: ChengyuZhu6 @ 2026-01-15  3:38 UTC (permalink / raw)
  To: linux-erofs; +Cc: hsiangkao, Chengyu Zhu

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, architecture, and variant) at compile time using
preprocessor macros.

Signed-off-by: Chengyu Zhu <hudsonzhu@tencent.com>
---
 lib/remotes/oci.c | 68 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 64 insertions(+), 4 deletions(-)

diff --git a/lib/remotes/oci.c b/lib/remotes/oci.c
index c8711ea..4c4568f 100644
--- a/lib/remotes/oci.c
+++ b/lib/remotes/oci.c
@@ -694,10 +694,20 @@ static char *ocierofs_get_manifest_digest(struct ocierofs_ctx *ctx,
 		    json_object_object_get_ex(manifest, "digest", &digest_obj)) {
 			const char *arch = json_object_get_string(arch_obj);
 			const char *os = json_object_get_string(os_obj);
+			json_object *variant_obj;
+			const char *variant = NULL;
 			char manifest_platform[64];
 
-			snprintf(manifest_platform, sizeof(manifest_platform),
-				 "%s/%s", os, arch);
+			if (json_object_object_get_ex(platform_obj, "variant", &variant_obj))
+				variant = json_object_get_string(variant_obj);
+
+			if (variant)
+				snprintf(manifest_platform, sizeof(manifest_platform),
+					 "%s/%s/%s", os, arch, variant);
+			else
+				snprintf(manifest_platform, sizeof(manifest_platform),
+					 "%s/%s", os, arch);
+
 			if (!strcmp(manifest_platform, platform)) {
 				digest = strdup(json_object_get_string(digest_obj));
 				break;
@@ -1089,13 +1099,63 @@ static int ocierofs_parse_ref(struct ocierofs_ctx *ctx, const char *ref_str)
 	return 0;
 }
 
+static char *ocierofs_get_platform_spec(void)
+{
+	const char *os = NULL, *arch = NULL, *variant = NULL;
+	char *platform;
+
+#if defined(__linux__)
+	os = "linux";
+#elif defined(__APPLE__)
+	os = "darwin";
+#elif defined(_WIN32)
+	os = "windows";
+#elif defined(__FreeBSD__)
+	os = "freebsd";
+#endif
+
+#if defined(__x86_64__) || defined(__amd64__)
+	arch = "amd64";
+#elif defined(__aarch64__) || defined(__arm64__)
+	arch = "arm64";
+	variant = "v8";
+#elif defined(__i386__)
+	arch = "386";
+#elif defined(__arm__)
+	arch = "arm";
+	variant = "v7";
+#elif defined(__riscv) && (__riscv_xlen == 64)
+	arch = "riscv64";
+#elif defined(__ppc64__)
+#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+	arch = "ppc64le";
+#else
+	arch = "ppc64";
+#endif
+#elif defined(__s390x__)
+	arch = "s390x";
+#endif
+
+	if (!os || !arch)
+		return NULL;
+
+	if (variant) {
+		if (asprintf(&platform, "%s/%s/%s", os, arch, variant) < 0)
+			return NULL;
+	} else {
+		if (asprintf(&platform, "%s/%s", os, arch) < 0)
+			return NULL;
+	}
+	return platform;
+}
+
 /**
  * ocierofs_init - Initialize OCI context
  * @ctx: OCI context structure to initialize
  * @config: OCI configuration
  *
  * Initialize OCI context structure, set up CURL handle, and configure
- * default parameters including platform (linux/amd64), registry
+ * default parameters including platform (host platform), registry
  * (registry-1.docker.io), and tag (latest).
  *
  * Return: 0 on success, negative errno on failure
@@ -1120,7 +1180,7 @@ static int ocierofs_init(struct ocierofs_ctx *ctx, const struct ocierofs_config
 	if (config->platform)
 		ctx->platform = strdup(config->platform);
 	else
-		ctx->platform = strdup("linux/amd64");
+		ctx->platform = ocierofs_get_platform_spec();
 	if (!ctx->registry || !ctx->tag || !ctx->platform)
 		return -ENOMEM;
 
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] erofs-utils: lib: oci: support auto-detecting host platform
  2026-01-15  3:38 ` [PATCH v2] " ChengyuZhu6
@ 2026-01-15  5:13   ` Gao Xiang
  0 siblings, 0 replies; 4+ messages in thread
From: Gao Xiang @ 2026-01-15  5:13 UTC (permalink / raw)
  To: ChengyuZhu6, linux-erofs; +Cc: Chengyu Zhu



On 2026/1/15 11:38, 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, architecture, and variant) at compile time using
> preprocessor macros.
> 
> Signed-off-by: Chengyu Zhu <hudsonzhu@tencent.com>
> ---
>   lib/remotes/oci.c | 68 ++++++++++++++++++++++++++++++++++++++++++++---
>   1 file changed, 64 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/remotes/oci.c b/lib/remotes/oci.c
> index c8711ea..4c4568f 100644
> --- a/lib/remotes/oci.c
> +++ b/lib/remotes/oci.c
> @@ -694,10 +694,20 @@ static char *ocierofs_get_manifest_digest(struct ocierofs_ctx *ctx,
>   		    json_object_object_get_ex(manifest, "digest", &digest_obj)) {
>   			const char *arch = json_object_get_string(arch_obj);
>   			const char *os = json_object_get_string(os_obj);
> +			json_object *variant_obj;
> +			const char *variant = NULL;
>   			char manifest_platform[64];
>   
> -			snprintf(manifest_platform, sizeof(manifest_platform),
> -				 "%s/%s", os, arch);
> +			if (json_object_object_get_ex(platform_obj, "variant", &variant_obj))
> +				variant = json_object_get_string(variant_obj);
> +
> +			if (variant)
> +				snprintf(manifest_platform, sizeof(manifest_platform),
> +					 "%s/%s/%s", os, arch, variant);
> +			else
> +				snprintf(manifest_platform, sizeof(manifest_platform),
> +					 "%s/%s", os, arch);
> +
>   			if (!strcmp(manifest_platform, platform)) {
>   				digest = strdup(json_object_get_string(digest_obj));
>   				break;
> @@ -1089,13 +1099,63 @@ static int ocierofs_parse_ref(struct ocierofs_ctx *ctx, const char *ref_str)
>   	return 0;
>   }
>   
> +static char *ocierofs_get_platform_spec(void)
> +{
> +	const char *os = NULL, *arch = NULL, *variant = NULL;
> +	char *platform;
> +
> +#if defined(__linux__)
> +	os = "linux";
> +#elif defined(__APPLE__)
> +	os = "darwin";
> +#elif defined(_WIN32)
> +	os = "windows";
> +#elif defined(__FreeBSD__)
> +	os = "freebsd";
> +#endif
> +
> +#if defined(__x86_64__) || defined(__amd64__)
> +	arch = "amd64";
> +#elif defined(__aarch64__) || defined(__arm64__)
> +	arch = "arm64";
> +	variant = "v8";
> +#elif defined(__i386__)
> +	arch = "386";
> +#elif defined(__arm__)
> +	arch = "arm";
> +	variant = "v7";
> +#elif defined(__riscv) && (__riscv_xlen == 64)
> +	arch = "riscv64";
> +#elif defined(__ppc64__)
> +#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
> +	arch = "ppc64le";
> +#else
> +	arch = "ppc64";
> +#endif
> +#elif defined(__s390x__)
> +	arch = "s390x";
> +#endif
> +
> +	if (!os || !arch)
> +		return NULL;
> +
> +	if (variant) {
> +		if (asprintf(&platform, "%s/%s/%s", os, arch, variant) < 0)
> +			return NULL;
> +	} else {
> +		if (asprintf(&platform, "%s/%s", os, arch) < 0)
> +			return NULL;
> +	}
> +	return platform;
> +}
> +
>   /**
>    * ocierofs_init - Initialize OCI context
>    * @ctx: OCI context structure to initialize
>    * @config: OCI configuration
>    *
>    * Initialize OCI context structure, set up CURL handle, and configure
> - * default parameters including platform (linux/amd64), registry
> + * default parameters including platform (host platform), registry
>    * (registry-1.docker.io), and tag (latest).
>    *
>    * Return: 0 on success, negative errno on failure
> @@ -1120,7 +1180,7 @@ static int ocierofs_init(struct ocierofs_ctx *ctx, const struct ocierofs_config
>   	if (config->platform)
>   		ctx->platform = strdup(config->platform);
>   	else
> -		ctx->platform = strdup("linux/amd64");
> +		ctx->platform = ocierofs_get_platform_spec();

	if (!ctx->platform)
		return -EOPNOTSUPP;

I will update this part manually, otherwise it looks good to me.

Thanks,
Gao Xiang


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-01-15  5:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-10  8:27 [PATCH v1] erofs-utils: lib: oci: support auto-detecting host platform ChengyuZhu6
2026-01-12  3:10 ` Gao Xiang
2026-01-15  3:38 ` [PATCH v2] " ChengyuZhu6
2026-01-15  5:13   ` Gao Xiang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.