diff --git a/NEWS b/NEWS
index 279715ee..4f9327de 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ TBD
* Prevent writing duplicate groups to metadata file
* Disable all filesystem access in flatpak-builder --run sandbox
* Add ability to set custom fusermount path
+* Support setting CGO buildflags and RUSTFLAGS in builder environment
Changes in 1.4.6
================
diff --git a/data/flatpak-manifest.schema.json b/data/flatpak-manifest.schema.json
index b9bb8be4..c478e84d 100644
--- a/data/flatpak-manifest.schema.json
+++ b/data/flatpak-manifest.schema.json
@@ -22,10 +22,18 @@
"description": "This is set in the environment variable CFLAGS during the build. Multiple specifications of this (in e.g. per-arch area) are concatenated, separated by spaces.",
"type": "string"
},
+ "cgo-cflags": {
+ "description": "This is set in the environment variable CGO_CFLAGS during the build. Multiple specifications of this (in e.g. per-arch area) are concatenated, separated by spaces. If unset, defaults to the value of cflags.",
+ "type": "string"
+ },
"cflags-override": {
"description": "If this is true, clear cflags from previous build options before adding it from these options.",
"type": "boolean"
},
+ "cgo-cflags-override": {
+ "description": "If this is true, clear cgo-cflags from previous build options before adding it from these options. If set without cgo-cflags, CGO_CFLAGS will not be set.",
+ "type": "boolean"
+ },
"cppflags": {
"description": "This is set in the environment variable CPPFLAGS during the build. Multiple specifications of this (in e.g. per-arch area) are concatenated, separated by spaces.",
"type": "string"
@@ -38,18 +46,42 @@
"description": "This is set in the environment variable CXXFLAGS during the build. Multiple specifications of this (in e.g. per-arch area) are concatenated, separated by spaces.",
"type": "string"
},
+ "cgo-cxxflags": {
+ "description": "This is set in the environment variable CGO_CXXFLAGS during the build. Multiple specifications of this (in e.g. per-arch area) are concatenated, separated by spaces. If unset, defaults to the value of cxxflags.",
+ "type": "string"
+ },
"cxxflags-override": {
"description": "If this is true, clear cxxflags from previous build options before adding it from these options.",
"type": "boolean"
},
+ "cgo-cxxflags-override": {
+ "description": "If this is true, clear cgo-cxxflags from previous build options before adding it from these options. If set without cgo-cxxflags, CGO_CXXFLAGS will not be set.",
+ "type": "boolean"
+ },
"ldflags": {
"description": "This is set in the environment variable LDFLAGS during the build. Multiple specifications of this (in e.g. per-arch area) are concatenated, separated by spaces.",
"type": "string"
},
+ "cgo-ldflags": {
+ "description": "This is set in the environment variable CGO_LDFLAGS during the build. Multiple specifications of this (in e.g. per-arch area) are concatenated, separated by spaces. If unset, defaults to the value of ldflags.",
+ "type": "string"
+ },
"ldflags-override": {
"description": "If this is true, clear ldflags from previous build options before adding it from these options.",
"type": "boolean"
},
+ "cgo-ldflags-override": {
+ "description": "If this is true, clear cgo-ldflags from previous build options before adding it from these options. If set without cgo-ldflags, CGO_LDFLAGS will not be set.",
+ "type": "boolean"
+ },
+ "rustflags": {
+ "description": "This is set in the environment variable RUSTFLAGS during the build. Multiple specifications of this (in e.g. per-arch area) are concatenated, separated by spaces.",
+ "type": "string"
+ },
+ "rustflags-override": {
+ "description": "If this is true, clear rustflags from previous build options before adding it from these options.",
+ "type": "boolean"
+ },
"prefix": {
"description": "The build prefix for the modules (defaults to /app for applications and /usr for runtimes).",
"type": "string"
diff --git a/doc/flatpak-manifest.xml b/doc/flatpak-manifest.xml
index a498d10e..eb2c7984 100644
--- a/doc/flatpak-manifest.xml
+++ b/doc/flatpak-manifest.xml
@@ -312,10 +312,18 @@
(string)
This is set in the environment variable CFLAGS during the build. Multiple specifications of this (in e.g. per-arch area) are concatenated, separated by spaces.
+
+ (string)
+ This is set in the environment variable CGO_CFLAGS during the build. Multiple specifications of this (in e.g. per-arch area) are concatenated, separated by spaces. If unset, defaults to the value of cflags.
+
(boolean)
If this is true, clear cflags from previous build options before adding it from these options.
+
+ (boolean)
+ If this is true, clear cgo-cflags from previous build options before adding it from these options. If set without cgo-cflags, CGO_CFLAGS will not be set.
+
(string)
This is set in the environment variable CPPFLAGS during the build. Multiple specifications of this (in e.g. per-arch area) are concatenated, separated by spaces.
@@ -328,18 +336,42 @@
(string)
This is set in the environment variable CXXFLAGS during the build. Multiple specifications of this (in e.g. per-arch area) are concatenated, separated by spaces.
+
+ (string)
+ This is set in the environment variable CGO_CXXFLAGS during the build. Multiple specifications of this (in e.g. per-arch area) are concatenated, separated by spaces. If unset, defaults to the value of cxxflags.
+
(boolean)
If this is true, clear cxxflags from previous build options before adding it from these options.
+
+ (boolean)
+ If this is true, clear cgo-cxxflags from previous build options before adding it from these options. If set without cgo-cxxflags, CGO_CXXFLAGS will not be set.
+
(string)
This is set in the environment variable LDFLAGS during the build. Multiple specifications of this (in e.g. per-arch area) are concatenated, separated by spaces.
+
+ (string)
+ This is set in the environment variable CGO_LDFLAGS during the build. Multiple specifications of this (in e.g. per-arch area) are concatenated, separated by spaces. If unset, defaults to the value of ldflags.
+
(boolean)
If this is true, clear ldflags from previous build options before adding it from these options.
+
+ (boolean)
+ If this is true, clear cgo-ldflags from previous build options before adding it from these options. If set without cgo-ldflags, CGO_LDFLAGS will not be set.
+
+
+ (string)
+ This is set in the environment variable RUSTFLAGS during the build. Multiple specifications of this (in e.g. per-arch area) are concatenated, separated by spaces.
+
+
+ (boolean)
+ If this is true, clear rustflags from previous build options before adding it from these options.
+
(string)
The build prefix for the modules (defaults to /app for
diff --git a/src/builder-options.c b/src/builder-options.c
index 8602a284..7762179a 100644
--- a/src/builder-options.c
+++ b/src/builder-options.c
@@ -40,13 +40,21 @@ struct BuilderOptions
gboolean no_debuginfo;
gboolean no_debuginfo_compression;
char *cflags;
+ char *cgo_cflags;
gboolean cflags_override;
+ gboolean cgo_cflags_override;
char *cppflags;
gboolean cppflags_override;
char *cxxflags;
+ char *cgo_cxxflags;
gboolean cxxflags_override;
+ gboolean cgo_cxxflags_override;
char *ldflags;
+ char *cgo_ldflags;
gboolean ldflags_override;
+ gboolean cgo_ldflags_override;
+ char *rustflags;
+ gboolean rustflags_override;
char *append_path;
char *prepend_path;
char *append_ld_library_path;
@@ -79,13 +87,21 @@ G_DEFINE_TYPE_WITH_CODE (BuilderOptions, builder_options, G_TYPE_OBJECT,
enum {
PROP_0,
PROP_CFLAGS,
+ PROP_CGO_CFLAGS,
PROP_CFLAGS_OVERRIDE,
+ PROP_CGO_CFLAGS_OVERRIDE,
PROP_CPPFLAGS,
PROP_CPPFLAGS_OVERRIDE,
PROP_CXXFLAGS,
+ PROP_CGO_CXXFLAGS,
PROP_CXXFLAGS_OVERRIDE,
+ PROP_CGO_CXXFLAGS_OVERRIDE,
PROP_LDFLAGS,
+ PROP_CGO_LDFLAGS,
PROP_LDFLAGS_OVERRIDE,
+ PROP_CGO_LDFLAGS_OVERRIDE,
+ PROP_RUSTFLAGS,
+ PROP_RUSTFLAGS_OVERRIDE,
PROP_PREFIX,
PROP_LIBDIR,
PROP_ENV,
@@ -116,9 +132,13 @@ builder_options_finalize (GObject *object)
BuilderOptions *self = (BuilderOptions *) object;
g_free (self->cflags);
+ g_free (self->cgo_cflags);
g_free (self->cxxflags);
+ g_free (self->cgo_cxxflags);
g_free (self->cppflags);
g_free (self->ldflags);
+ g_free (self->cgo_ldflags);
+ g_free (self->rustflags);
g_free (self->append_path);
g_free (self->prepend_path);
g_free (self->append_ld_library_path);
@@ -154,10 +174,18 @@ builder_options_get_property (GObject *object,
g_value_set_string (value, self->cflags);
break;
+ case PROP_CGO_CFLAGS:
+ g_value_set_string (value, self->cgo_cflags);
+ break;
+
case PROP_CFLAGS_OVERRIDE:
g_value_set_boolean (value, self->cflags_override);
break;
+ case PROP_CGO_CFLAGS_OVERRIDE:
+ g_value_set_boolean (value, self->cgo_cflags_override);
+ break;
+
case PROP_CPPFLAGS:
g_value_set_string (value, self->cppflags);
break;
@@ -170,18 +198,42 @@ builder_options_get_property (GObject *object,
g_value_set_string (value, self->cxxflags);
break;
+ case PROP_CGO_CXXFLAGS:
+ g_value_set_string (value, self->cgo_cxxflags);
+ break;
+
case PROP_CXXFLAGS_OVERRIDE:
g_value_set_boolean (value, self->cxxflags_override);
break;
+ case PROP_CGO_CXXFLAGS_OVERRIDE:
+ g_value_set_boolean (value, self->cgo_cxxflags_override);
+ break;
+
case PROP_LDFLAGS:
g_value_set_string (value, self->ldflags);
break;
+ case PROP_CGO_LDFLAGS:
+ g_value_set_string (value, self->cgo_ldflags);
+ break;
+
case PROP_LDFLAGS_OVERRIDE:
g_value_set_boolean (value, self->ldflags_override);
break;
+ case PROP_CGO_LDFLAGS_OVERRIDE:
+ g_value_set_boolean (value, self->cgo_ldflags_override);
+ break;
+
+ case PROP_RUSTFLAGS:
+ g_value_set_string (value, self->rustflags);
+ break;
+
+ case PROP_RUSTFLAGS_OVERRIDE:
+ g_value_set_boolean (value, self->rustflags_override);
+ break;
+
case PROP_APPEND_PATH:
g_value_set_string (value, self->append_path);
break;
@@ -283,19 +335,37 @@ builder_options_set_property (GObject *object,
self->cflags = g_value_dup_string (value);
break;
+ case PROP_CGO_CFLAGS:
+ g_clear_pointer (&self->cgo_cflags, g_free);
+ self->cgo_cflags = g_value_dup_string (value);
+ break;
+
case PROP_CFLAGS_OVERRIDE:
self->cflags_override = g_value_get_boolean (value);
break;
+ case PROP_CGO_CFLAGS_OVERRIDE:
+ self->cgo_cflags_override = g_value_get_boolean (value);
+ break;
+
case PROP_CXXFLAGS:
g_clear_pointer (&self->cxxflags, g_free);
self->cxxflags = g_value_dup_string (value);
break;
+ case PROP_CGO_CXXFLAGS:
+ g_clear_pointer (&self->cgo_cxxflags, g_free);
+ self->cgo_cxxflags = g_value_dup_string (value);
+ break;
+
case PROP_CXXFLAGS_OVERRIDE:
self->cxxflags_override = g_value_get_boolean (value);
break;
+ case PROP_CGO_CXXFLAGS_OVERRIDE:
+ self->cgo_cxxflags_override = g_value_get_boolean (value);
+ break;
+
case PROP_CPPFLAGS:
g_clear_pointer (&self->cppflags, g_free);
self->cppflags = g_value_dup_string (value);
@@ -310,10 +380,28 @@ builder_options_set_property (GObject *object,
self->ldflags = g_value_dup_string (value);
break;
+ case PROP_CGO_LDFLAGS:
+ g_clear_pointer (&self->cgo_ldflags, g_free);
+ self->cgo_ldflags = g_value_dup_string (value);
+ break;
+
case PROP_LDFLAGS_OVERRIDE:
self->ldflags_override = g_value_get_boolean (value);
break;
+ case PROP_CGO_LDFLAGS_OVERRIDE:
+ self->cgo_ldflags_override = g_value_get_boolean (value);
+ break;
+
+ case PROP_RUSTFLAGS:
+ g_clear_pointer (&self->rustflags, g_free);
+ self->rustflags = g_value_dup_string (value);
+ break;
+
+ case PROP_RUSTFLAGS_OVERRIDE:
+ self->rustflags_override = g_value_get_boolean (value);
+ break;
+
case PROP_APPEND_PATH:
g_clear_pointer (&self->append_path, g_free);
self->append_path = g_value_dup_string (value);
@@ -441,6 +529,13 @@ builder_options_class_init (BuilderOptionsClass *klass)
"",
NULL,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_CGO_CFLAGS,
+ g_param_spec_string ("cgo-cflags",
+ "",
+ "",
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_CFLAGS_OVERRIDE,
g_param_spec_boolean ("cflags-override",
@@ -448,6 +543,13 @@ builder_options_class_init (BuilderOptionsClass *klass)
"",
FALSE,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_CGO_CFLAGS_OVERRIDE,
+ g_param_spec_boolean ("cgo-cflags-override",
+ "",
+ "",
+ FALSE,
+ G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_CXXFLAGS,
g_param_spec_string ("cxxflags",
@@ -455,6 +557,13 @@ builder_options_class_init (BuilderOptionsClass *klass)
"",
NULL,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_CGO_CXXFLAGS,
+ g_param_spec_string ("cgo-cxxflags",
+ "",
+ "",
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_CXXFLAGS_OVERRIDE,
g_param_spec_boolean ("cxxflags-override",
@@ -462,6 +571,13 @@ builder_options_class_init (BuilderOptionsClass *klass)
"",
FALSE,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_CGO_CXXFLAGS_OVERRIDE,
+ g_param_spec_boolean ("cgo-cxxflags-override",
+ "",
+ "",
+ FALSE,
+ G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_CPPFLAGS,
g_param_spec_string ("cppflags",
@@ -483,6 +599,13 @@ builder_options_class_init (BuilderOptionsClass *klass)
"",
NULL,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_CGO_LDFLAGS,
+ g_param_spec_string ("cgo-ldflags",
+ "",
+ "",
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_LDFLAGS_OVERRIDE,
g_param_spec_boolean ("ldflags-override",
@@ -490,6 +613,21 @@ builder_options_class_init (BuilderOptionsClass *klass)
"",
FALSE,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_CGO_LDFLAGS_OVERRIDE,
+ g_param_spec_boolean ("cgo-ldflags-override",
+ "",
+ "",
+ FALSE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_RUSTFLAGS,
+ g_param_spec_string ("rustflags", "", "", NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_RUSTFLAGS_OVERRIDE,
+ g_param_spec_boolean ("rustflags-override", "", "", FALSE,
+ G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_APPEND_PATH,
g_param_spec_string ("append-path",
@@ -913,6 +1051,24 @@ get_sdk_flags (BuilderOptions *self, BuilderContext *context, const char *(*meth
return NULL;
}
+static gboolean
+builder_options_has_cgo_override (BuilderOptions *self,
+ BuilderContext *context,
+ size_t override_field_offset)
+{
+ g_autoptr(GList) options = get_all_options (self, context);
+ GList *l;
+
+ for (l = options; l != NULL; l = l->next)
+ {
+ BuilderOptions *o = l->data;
+ if (G_STRUCT_MEMBER (gboolean, o, override_field_offset))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
char *
builder_options_get_cflags (BuilderOptions *self, BuilderContext *context)
{
@@ -921,6 +1077,19 @@ builder_options_get_cflags (BuilderOptions *self, BuilderContext *context)
get_sdk_flags (self, context, builder_sdk_config_get_cflags));
}
+char *
+builder_options_get_cgo_cflags (BuilderOptions *self, BuilderContext *context)
+{
+ char *result = builder_options_get_flags (self, context,
+ G_STRUCT_OFFSET (BuilderOptions, cgo_cflags),
+ G_STRUCT_OFFSET (BuilderOptions, cgo_cflags_override),
+ NULL);
+ if (result || builder_options_has_cgo_override (self, context,
+ G_STRUCT_OFFSET (BuilderOptions, cgo_cflags_override)))
+ return result;
+ return builder_options_get_cflags (self, context);
+}
+
char *
builder_options_get_cxxflags (BuilderOptions *self, BuilderContext *context)
{
@@ -929,6 +1098,20 @@ builder_options_get_cxxflags (BuilderOptions *self, BuilderContext *context)
get_sdk_flags (self, context, builder_sdk_config_get_cxxflags));
}
+char *
+builder_options_get_cgo_cxxflags (BuilderOptions *self, BuilderContext *context)
+{
+ char *result = builder_options_get_flags (self, context,
+ G_STRUCT_OFFSET (BuilderOptions, cgo_cxxflags),
+ G_STRUCT_OFFSET (BuilderOptions, cgo_cxxflags_override),
+ NULL);
+ if (result || builder_options_has_cgo_override (self, context,
+ G_STRUCT_OFFSET (BuilderOptions, cgo_cxxflags_override)))
+ return result;
+ return builder_options_get_cxxflags (self, context);
+}
+
+
char *
builder_options_get_cppflags (BuilderOptions *self, BuilderContext *context)
{
@@ -945,6 +1128,28 @@ builder_options_get_ldflags (BuilderOptions *self, BuilderContext *context)
get_sdk_flags (self, context, builder_sdk_config_get_ldflags));
}
+char *
+builder_options_get_cgo_ldflags (BuilderOptions *self, BuilderContext *context)
+{
+ char *result = builder_options_get_flags (self, context,
+ G_STRUCT_OFFSET (BuilderOptions, cgo_ldflags),
+ G_STRUCT_OFFSET (BuilderOptions, cgo_ldflags_override),
+ NULL);
+ if (result || builder_options_has_cgo_override (self, context,
+ G_STRUCT_OFFSET (BuilderOptions, cgo_ldflags_override)))
+ return result;
+ return builder_options_get_ldflags (self, context);
+}
+
+char *
+builder_options_get_rustflags (BuilderOptions *self, BuilderContext *context)
+{
+ return builder_options_get_flags (self, context,
+ G_STRUCT_OFFSET (BuilderOptions, rustflags),
+ G_STRUCT_OFFSET (BuilderOptions, rustflags_override),
+ get_sdk_flags (self, context, builder_sdk_config_get_rustflags));
+}
+
static char *
builder_options_get_appended_path (BuilderOptions *self, BuilderContext *context, const char *initial_value, size_t append_field_offset, size_t prepend_field_offset)
{
@@ -1135,9 +1340,13 @@ builder_options_get_env (BuilderOptions *self, BuilderContext *context)
int i;
char **envp = NULL;
g_autofree char *cflags = NULL;
+ g_autofree char *cgo_cflags = NULL;
g_autofree char *cppflags = NULL;
g_autofree char *cxxflags = NULL;
+ g_autofree char *cgo_cxxflags = NULL;
g_autofree char *ldflags = NULL;
+ g_autofree char *cgo_ldflags = NULL;
+ g_autofree char *rustflags = NULL;
envp = builder_context_extend_env_pre (context, envp);
@@ -1145,6 +1354,10 @@ builder_options_get_env (BuilderOptions *self, BuilderContext *context)
if (cflags)
envp = g_environ_setenv (envp, "CFLAGS", cflags, FALSE);
+ cgo_cflags = builder_options_get_cgo_cflags (self, context);
+ if (cgo_cflags)
+ envp = g_environ_setenv (envp, "CGO_CFLAGS", cgo_cflags, FALSE);
+
cppflags = builder_options_get_cppflags (self, context);
if (cppflags)
envp = g_environ_setenv (envp, "CPPFLAGS", cppflags, FALSE);
@@ -1153,10 +1366,22 @@ builder_options_get_env (BuilderOptions *self, BuilderContext *context)
if (cxxflags)
envp = g_environ_setenv (envp, "CXXFLAGS", cxxflags, FALSE);
+ cgo_cxxflags = builder_options_get_cgo_cxxflags (self, context);
+ if (cgo_cxxflags)
+ envp = g_environ_setenv (envp, "CGO_CXXFLAGS", cgo_cxxflags, FALSE);
+
ldflags = builder_options_get_ldflags (self, context);
if (ldflags)
envp = g_environ_setenv (envp, "LDFLAGS", ldflags, FALSE);
+ cgo_ldflags = builder_options_get_cgo_ldflags (self, context);
+ if (cgo_ldflags)
+ envp = g_environ_setenv (envp, "CGO_LDFLAGS", cgo_ldflags, FALSE);
+
+ rustflags = builder_options_get_rustflags (self, context);
+ if (rustflags)
+ envp = g_environ_setenv (envp, "RUSTFLAGS", rustflags, FALSE);
+
/* We traverse in reverse order because the list is "last first" */
for (l = g_list_last (options); l != NULL; l = l->prev)
{
@@ -1391,13 +1616,21 @@ builder_options_checksum (BuilderOptions *self,
builder_cache_checksum_str (cache, BUILDER_OPTION_CHECKSUM_VERSION);
builder_cache_checksum_str (cache, self->cflags);
+ builder_cache_checksum_str (cache, self->cgo_cflags);
builder_cache_checksum_compat_boolean (cache, self->cflags_override);
+ builder_cache_checksum_compat_boolean (cache, self->cgo_cflags_override);
builder_cache_checksum_str (cache, self->cxxflags);
+ builder_cache_checksum_str (cache, self->cgo_cxxflags);
builder_cache_checksum_compat_boolean (cache, self->cxxflags_override);
+ builder_cache_checksum_compat_boolean (cache, self->cgo_cxxflags_override);
builder_cache_checksum_str (cache, self->cppflags);
builder_cache_checksum_compat_boolean (cache, self->cppflags_override);
builder_cache_checksum_str (cache, self->ldflags);
+ builder_cache_checksum_str (cache, self->cgo_ldflags);
builder_cache_checksum_compat_boolean (cache, self->ldflags_override);
+ builder_cache_checksum_compat_boolean (cache, self->cgo_ldflags_override);
+ builder_cache_checksum_str (cache, self->rustflags);
+ builder_cache_checksum_compat_boolean (cache, self->rustflags_override);
builder_cache_checksum_str (cache, self->prefix);
builder_cache_checksum_compat_str (cache, self->libdir);
builder_cache_checksum_strv (cache, self->env);
diff --git a/src/builder-options.h b/src/builder-options.h
index 3eec8e35..8efa5eba 100644
--- a/src/builder-options.h
+++ b/src/builder-options.h
@@ -39,12 +39,20 @@ GType builder_options_get_type (void);
char *builder_options_get_cflags (BuilderOptions *self,
BuilderContext *context);
+char *builder_options_get_cgo_cflags (BuilderOptions *self,
+ BuilderContext *context);
char *builder_options_get_cxxflags (BuilderOptions *self,
BuilderContext *context);
+char *builder_options_get_cgo_cxxflags (BuilderOptions *self,
+ BuilderContext *context);
char *builder_options_get_cppflags (BuilderOptions *self,
BuilderContext *context);
char *builder_options_get_ldflags (BuilderOptions *self,
BuilderContext *context);
+char *builder_options_get_cgo_ldflags (BuilderOptions *self,
+ BuilderContext *context);
+char *builder_options_get_rustflags (BuilderOptions *self,
+ BuilderContext *context);
const char *builder_options_get_prefix (BuilderOptions *self,
BuilderContext *context);
const char *builder_options_get_libdir (BuilderOptions *self,
diff --git a/src/builder-sdk-config.c b/src/builder-sdk-config.c
index d7601974..f99973d4 100644
--- a/src/builder-sdk-config.c
+++ b/src/builder-sdk-config.c
@@ -30,6 +30,7 @@ struct BuilderSdkConfig {
char *cflags;
char *cxxflags;
char *ldflags;
+ char *rustflags;
};
typedef struct
@@ -49,6 +50,7 @@ builder_sdk_config_finalize (GObject *object)
g_free (self->cflags);
g_free (self->cxxflags);
g_free (self->ldflags);
+ g_free (self->rustflags);
G_OBJECT_CLASS (builder_sdk_config_parent_class)->finalize (object);
}
@@ -60,6 +62,7 @@ enum {
PROP_CFLAGS,
PROP_CXXFLAGS,
PROP_LDFLAGS,
+ PROP_RUSTFLAGS,
LAST_PROP
};
@@ -93,6 +96,10 @@ builder_sdk_config_get_property (GObject *object,
g_value_set_string (value, self->ldflags);
break;
+ case PROP_RUSTFLAGS:
+ g_value_set_string (value, self->rustflags);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -132,6 +139,11 @@ builder_sdk_config_set_property (GObject *object,
g_free (self->ldflags);
self->ldflags = g_value_dup_string(value);
break ;
+
+ case PROP_RUSTFLAGS:
+ g_free (self->rustflags);
+ self->rustflags = g_value_dup_string(value);
+ break ;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -181,6 +193,13 @@ builder_sdk_config_class_init (BuilderSdkConfigClass *klass)
"",
NULL,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_RUSTFLAGS,
+ g_param_spec_string ("rustflags",
+ "",
+ "",
+ NULL,
+ G_PARAM_READWRITE));
}
static void
@@ -219,6 +238,12 @@ builder_sdk_config_get_ldflags (BuilderSdkConfig *self)
return self->ldflags;
}
+const char *
+builder_sdk_config_get_rustflags (BuilderSdkConfig *self)
+{
+ return self->rustflags;
+}
+
BuilderSdkConfig *
builder_sdk_config_from_file (GFile *file,
GError **error)
diff --git a/src/builder-sdk-config.h b/src/builder-sdk-config.h
index 1b4d67ba..389ae225 100644
--- a/src/builder-sdk-config.h
+++ b/src/builder-sdk-config.h
@@ -38,6 +38,7 @@ const char * builder_sdk_config_get_cppflags (BuilderSdkConfig *self);
const char * builder_sdk_config_get_cflags (BuilderSdkConfig *self);
const char * builder_sdk_config_get_cxxflags (BuilderSdkConfig *self);
const char * builder_sdk_config_get_ldflags (BuilderSdkConfig *self);
+const char *builder_sdk_config_get_rustflags (BuilderSdkConfig *self);
BuilderSdkConfig *builder_sdk_config_from_file (GFile *file,
GError **error);
diff --git a/tests/meson.build b/tests/meson.build
index c1fda2cb..ff701571 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -12,6 +12,7 @@ test_names = [
'test-builder',
'test-builder-deprecated',
'test-builder-python',
+ 'test-builder-flags',
]
tap_test = find_program(
diff --git a/tests/test-builder-flags.sh b/tests/test-builder-flags.sh
new file mode 100755
index 00000000..4602a9a4
--- /dev/null
+++ b/tests/test-builder-flags.sh
@@ -0,0 +1,229 @@
+#!/bin/bash
+#
+# Copyright (C) 2026 Boudhayan Bhattacharya
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+set -euo pipefail
+
+. $(dirname $0)/libtest.sh
+
+skip_without_fuse
+
+echo "1..8"
+
+setup_repo
+install_repo
+setup_sdk_repo
+install_sdk_repo
+
+cd "$TEST_DATA_DIR"
+
+run_build () {
+ local manifest=$1
+ ${FLATPAK_BUILDER} --force-clean appdir "$manifest" >&2
+}
+
+# No cgo-cflags: CGO_CFLAGS should equal CFLAGS
+cat > test-cgo-default.json <<'EOF'
+{
+ "app-id": "org.test.CgoDefault",
+ "runtime": "org.test.Platform",
+ "sdk": "org.test.Sdk",
+ "build-options": {
+ "cflags": "-O2 -g"
+ },
+ "modules": [{
+ "name": "test",
+ "buildsystem": "simple",
+ "build-commands": [
+ "echo $CFLAGS > /app/cflags_out",
+ "echo $CGO_CFLAGS > /app/cgo_cflags_out"
+ ]
+ }]
+}
+EOF
+run_build test-cgo-default.json
+assert_file_has_content appdir/files/cflags_out '\-O2 \-g'
+assert_file_has_content appdir/files/cgo_cflags_out '\-O2 \-g'
+echo "ok cgo-cflags defaults to cflags"
+
+# cgo-cflags set: CGO_CFLAGS should use that value
+cat > test-cgo-set.json <<'EOF'
+{
+ "app-id": "org.test.CgoSet",
+ "runtime": "org.test.Platform",
+ "sdk": "org.test.Sdk",
+ "build-options": {
+ "cflags": "-O2 -g",
+ "cgo-cflags": "-O0"
+ },
+ "modules": [{
+ "name": "test",
+ "buildsystem": "simple",
+ "build-commands": [
+ "echo $CFLAGS > /app/cflags_out",
+ "echo $CGO_CFLAGS > /app/cgo_cflags_out"
+ ]
+ }]
+}
+EOF
+run_build test-cgo-set.json
+assert_file_has_content appdir/files/cflags_out '\-O2 \-g'
+assert_file_has_content appdir/files/cgo_cflags_out '\-O0'
+assert_not_file_has_content appdir/files/cgo_cflags_out '\-O2'
+echo "ok cgo-cflags overrides cflags fallback"
+
+# cgo-cflags-override without cgo-cflags: CGO_CFLAGS should not be set
+cat > test-cgo-override-empty.json <<'EOF'
+{
+ "app-id": "org.test.CgoOverrideEmpty",
+ "runtime": "org.test.Platform",
+ "sdk": "org.test.Sdk",
+ "build-options": {
+ "cflags": "-O2 -g",
+ "cgo-cflags-override": true
+ },
+ "modules": [{
+ "name": "test",
+ "buildsystem": "simple",
+ "build-commands": [
+ "echo ${CGO_CFLAGS:-unset} > /app/cgo_cflags_out"
+ ]
+ }]
+}
+EOF
+run_build test-cgo-override-empty.json
+assert_file_has_content appdir/files/cgo_cflags_out '^unset$'
+echo "ok cgo-cflags-override without cgo-cflags suppresses fallback"
+
+# No cgo-cxxflags set: CGO_CXXFLAGS should equal CXXFLAGS
+cat > test-cgo-cxx-default.json <<'EOF'
+{
+ "app-id": "org.test.CgoCxxDefault",
+ "runtime": "org.test.Platform",
+ "sdk": "org.test.Sdk",
+ "build-options": {
+ "cxxflags": "-O2 -g"
+ },
+ "modules": [{
+ "name": "test",
+ "buildsystem": "simple",
+ "build-commands": [
+ "echo $CXXFLAGS > /app/cxxflags_out",
+ "echo $CGO_CXXFLAGS > /app/cgo_cxxflags_out"
+ ]
+ }]
+}
+EOF
+run_build test-cgo-cxx-default.json
+assert_file_has_content appdir/files/cxxflags_out '\-O2 \-g'
+assert_file_has_content appdir/files/cgo_cxxflags_out '\-O2 \-g'
+echo "ok cgo-cxxflags defaults to cxxflags"
+
+# cgo-cxxflags set: CGO_CXXFLAGS should use that value
+cat > test-cgo-cxx-set.json <<'EOF'
+{
+ "app-id": "org.test.CgoCxxSet",
+ "runtime": "org.test.Platform",
+ "sdk": "org.test.Sdk",
+ "build-options": {
+ "cxxflags": "-O2 -g",
+ "cgo-cxxflags": "-O0"
+ },
+ "modules": [{
+ "name": "test",
+ "buildsystem": "simple",
+ "build-commands": [
+ "echo $CXXFLAGS > /app/cxxflags_out",
+ "echo $CGO_CXXFLAGS > /app/cgo_cxxflags_out"
+ ]
+ }]
+}
+EOF
+run_build test-cgo-cxx-set.json
+assert_file_has_content appdir/files/cxxflags_out '\-O2 \-g'
+assert_file_has_content appdir/files/cgo_cxxflags_out '\-O0'
+assert_not_file_has_content appdir/files/cgo_cxxflags_out '\-O2'
+echo "ok cgo-cxxflags overrides cxxflags fallback"
+
+# RUSTFLAGS should be passed
+cat > test-rustflags-set.json <<'EOF'
+{
+ "app-id": "org.test.RustflagsSet",
+ "runtime": "org.test.Platform",
+ "sdk": "org.test.Sdk",
+ "build-options": {
+ "rustflags": "-C opt-level=2"
+ },
+ "modules": [{
+ "name": "test",
+ "buildsystem": "simple",
+ "build-commands": [
+ "echo ${RUSTFLAGS} > /app/rustflags_out"
+ ]
+ }]
+}
+EOF
+run_build test-rustflags-set.json
+assert_file_has_content appdir/files/rustflags_out '\-C opt\-level=2'
+echo "ok rustflags is set"
+
+# RUSTFLAGS should be unset as test SDK doesn't ship any flags
+cat > test-rustflags-unset.json <<'EOF'
+{
+ "app-id": "org.test.RustflagsUnset",
+ "runtime": "org.test.Platform",
+ "sdk": "org.test.Sdk",
+ "modules": [{
+ "name": "test",
+ "buildsystem": "simple",
+ "build-commands": [
+ "echo ${RUSTFLAGS:-unset} > /app/rustflags_out"
+ ]
+ }]
+}
+EOF
+run_build test-rustflags-unset.json
+assert_file_has_content appdir/files/rustflags_out '^unset$'
+echo "ok rustflags unset when not specified"
+
+# rustflags-override at module level clears manifest-level rustflags
+cat > test-rustflags-override.json <<'EOF'
+{
+ "app-id": "org.test.RustflagsOverride",
+ "runtime": "org.test.Platform",
+ "sdk": "org.test.Sdk",
+ "build-options": {
+ "rustflags": "-C debuginfo=0"
+ },
+ "modules": [{
+ "name": "test",
+ "buildsystem": "simple",
+ "build-options": {
+ "rustflags": "-C opt-level=3",
+ "rustflags-override": true
+ },
+ "build-commands": [
+ "echo ${RUSTFLAGS} > /app/rustflags_out"
+ ]
+ }]
+}
+EOF
+run_build test-rustflags-override.json
+assert_file_has_content appdir/files/rustflags_out '\-C opt\-level=3'
+assert_not_file_has_content appdir/files/rustflags_out 'debuginfo'
+echo "ok rustflags-override at module level clears manifest-level rustflags"