Skip to content

Commit 926ef5a

Browse files
authored
Fix cross-compilation for aarch64 on Ubuntu 25.10 (project-chip#43706)
* Fix cross-compilation for aarch64 on Ubuntu 25.10 * Post-process generated stub files instead of adding definition to command line
1 parent 107f97a commit 926ef5a

2 files changed

Lines changed: 38 additions & 68 deletions

File tree

build/chip/linux/gdbus_library.gni

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ template("gdbus_library") {
3636
}
3737

3838
config("${library_name}_compile_config") {
39-
# dbus code generation may generate some code detected as unreacheable
40-
# by recent enough clang
39+
# D-Bus code generation may generate some code detected as unreachable
40+
# by recent enough clang.
4141
cflags = [ "-Wno-unreachable-code" ]
4242
}
4343

@@ -64,31 +64,25 @@ template("gdbus_library") {
6464
]
6565

6666
args = [
67-
"--input",
68-
"{{source}}",
69-
"--output_c",
67+
"--output-c",
7068
rebase_path(source_file, root_build_dir),
71-
"--output_h",
69+
"--output-h",
7270
rebase_path(header_file, root_build_dir),
7371
]
7472

7573
if (defined(invoker.c_namespace)) {
76-
args += [
77-
"--c-namespace",
78-
invoker.c_namespace,
79-
]
74+
args += [ "--c-namespace=" + invoker.c_namespace ]
8075
}
8176

8277
if (defined(invoker.interface_prefix)) {
83-
args += [
84-
"--interface-prefix",
85-
invoker.interface_prefix,
86-
]
78+
args += [ "--interface-prefix=" + invoker.interface_prefix ]
8779
}
8880

8981
if (invoker.c_generate_object_manager) {
9082
args += [ "--c-generate-object-manager" ]
9183
}
84+
85+
args += [ "{{source}}" ]
9286
}
9387

9488
static_library(library_name) {

build/chip/linux/gen_gdbus_wrapper.py

Lines changed: 30 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,66 +19,42 @@
1919
import sys
2020

2121

22-
def main(argv):
23-
parser = argparse.ArgumentParser(description=("Generate dbus bindings."))
24-
25-
parser.add_argument("--input_file",
26-
required=True,
27-
help="The dbus service definition XML file.")
28-
29-
parser.add_argument(
30-
"--output_c",
31-
help="The source file to generate containing the GDBus proxy implementation"
32-
)
33-
34-
parser.add_argument(
35-
"--output_h",
36-
help="The header file to generate containing the GDBus proxy interface"
37-
)
38-
39-
parser.add_argument("--c-namespace",
40-
default=None,
41-
help="Prefix APIs with C namespace")
42-
43-
parser.add_argument("--interface-prefix",
44-
default=None,
45-
help="Add interface prefix")
46-
47-
parser.add_argument("--c-generate-object-manager",
48-
default=False, action='store_true',
49-
help="Generate object manager")
50-
51-
options = parser.parse_args(argv)
52-
53-
extra_args = []
54-
if options.c_namespace:
55-
extra_args += ["--c-namespace", options.c_namespace]
56-
57-
if options.interface_prefix:
58-
extra_args += ["--interface-prefix", options.interface_prefix]
59-
60-
if options.c_generate_object_manager:
61-
extra_args += ["--c-generate-object-manager"]
22+
def main():
23+
parser = argparse.ArgumentParser(description="Generate D-Bus bindings")
24+
parser.add_argument("--output-c",
25+
help="The source file to generate containing the GDBus proxy implementation")
26+
parser.add_argument("--output-h",
27+
help="The header file to generate containing the GDBus proxy interface")
28+
# Parse our options and forward anything else.
29+
options, extra_args = parser.parse_known_args()
6230

6331
if options.output_c:
64-
gdbus_args = ["gdbus-codegen", "--body", "--output", options.output_c
65-
] + extra_args + [options.input_file]
66-
subprocess.check_call(gdbus_args)
67-
sed_args = ["sed", "-i",
68-
r"s/config\.h/BuildConfig.h/g", options.output_c]
69-
if sys.platform == "darwin":
70-
sed_args = ["sed", "-i", "",
71-
r"s/config\.h/BuildConfig.h/g", options.output_c]
72-
subprocess.check_call(sed_args)
32+
subprocess.check_call(["gdbus-codegen", "--body", "--output", options.output_c] + extra_args)
33+
with open(options.output_c) as f:
34+
content = f.read()
35+
# Replace configuration header file generated by gdbus-codegen.
36+
content = content.replace('include "config.h"', 'include "BuildConfig.h"')
37+
with open(options.output_c, "w") as f:
38+
f.write(content)
7339

7440
if options.output_h:
75-
gdbus_args = [
76-
"gdbus-codegen", "--header", "--output", options.output_h
77-
] + extra_args + [options.input_file]
78-
subprocess.check_call(gdbus_args)
41+
subprocess.check_call(["gdbus-codegen", "--header", "--output", options.output_h] + extra_args)
42+
with open(options.output_h) as f:
43+
content = f.read()
44+
# Code generated with new gdbus-codegen adds checks for `GLIB_VERSION_2_84` which might
45+
# not yet be defined when compiling with older glib versions (e.g. cross-compilation).
46+
# This manually provided definition solves the problem with undefined identifiers.
47+
content = content.replace("G_BEGIN_DECLS", """
48+
#ifndef GLIB_VERSION_2_84
49+
#define GLIB_VERSION_2_84 G_ENCODE_VERSION(2, 84)
50+
#endif
51+
G_BEGIN_DECLS
52+
""")
53+
with open(options.output_h, "w") as f:
54+
f.write(content)
7955

8056
return 0
8157

8258

8359
if __name__ == '__main__':
84-
sys.exit(main(sys.argv[1:]))
60+
sys.exit(main())

0 commit comments

Comments
 (0)