Skip to content

Commit e330eb4

Browse files
committed
Port original CMake + MSYS2 patches to Meson
Tested with multiple configurations on Linux and with MSYS2 x86_64 native compilation on Windows.
1 parent 52e4317 commit e330eb4

49 files changed

Lines changed: 3783 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

VERSION.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.0

completions/fix_completions.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright 2025 meator
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""Helper script which fixes upstream shell completions.
18+
19+
See https://github.com/nmeum/android-tools/issues/22.
20+
21+
Input is provided via stdin and output is written to stdout.
22+
23+
This script is provided by android-tools-static, not by nmeum/android-tools.
24+
nmeum/android-tools uses a different approach to solve this issue: it keeps upstream
25+
completions intact and it provides a wrapper script which fixes the completions up and
26+
then sources the upstream completions. This approach doesn't work in release archives,
27+
this script keeps the completions in a single file which is more flexible.
28+
"""
29+
30+
import argparse
31+
import shutil
32+
import sys
33+
34+
_prefix = """
35+
# See https://github.com/nmeum/android-tools/issues/22
36+
37+
function check_type() {
38+
type -t "$1"
39+
}
40+
41+
""".lstrip()
42+
43+
if __name__ == "__main__":
44+
argparse.ArgumentParser(
45+
description=__doc__,
46+
formatter_class=argparse.RawDescriptionHelpFormatter,
47+
).parse_args()
48+
49+
sys.stdout.write(_prefix)
50+
sys.stdout.flush()
51+
52+
shutil.copyfileobj(sys.stdin.buffer, sys.stdout.buffer, length=1024 * 64)

completions/meson.build

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2025 meator
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
completionsdir = get_option('datadir') / 'bash-completion/completions'
16+
17+
custom_target(
18+
input: '../vendor/core/fastboot/fastboot.bash',
19+
output: 'fastboot',
20+
command: 'fix_completions.py',
21+
feed: true,
22+
capture: true,
23+
install: true,
24+
install_dir: completionsdir
25+
)
26+
27+
custom_target(
28+
input: '../vendor/adb/adb.bash',
29+
output: 'adb',
30+
command: 'fix_completions.py',
31+
feed: true,
32+
capture: true,
33+
install: true,
34+
install_dir: completionsdir
35+
)

meson.build

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Copyright 2025 meator
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
project(
16+
'android-tools-static',
17+
'c', 'cpp',
18+
version: files('VERSION.txt'),
19+
license: 'Apache-2.0',
20+
default_options: [
21+
# android-tools and its dependencies produce a crap ton of warnings.
22+
# since this project won't attempt to fix them (it is just a build system
23+
# port), do not enable extensive warnings.
24+
'warning_level=0',
25+
'c_std=gnu11',
26+
'cpp_std=gnu++20',
27+
],
28+
# The protobuf wrap is the wrap which requires the newest Meson.
29+
# meson_version is set to the highest requirement of any of its wraps.
30+
meson_version: '>=0.63.0'
31+
)
32+
33+
if meson.get_compiler('cpp').get_id() == 'msvc'
34+
error(
35+
'android-tools is not compatible with native MSVC! A Cygwin-like',
36+
'environmentis needed to compile this project (for example Cygwin, MSYS2).'
37+
)
38+
endif
39+
40+
if host_machine.endian() == 'big'
41+
error(
42+
'One of android-tools\' internal dependencies, BoringSSL, is incompatible',
43+
'with big endian systems such as ppc and ppc64 (but not ppc64le). Please',
44+
'see the following link for more info:',
45+
'https://boringssl.googlesource.com/boringssl/+/9cffd74fdb65c69506a0ce1b19420a67ad0cb19e/include/openssl/target.h#58'
46+
)
47+
endif
48+
49+
# Android provides it's own version of mke2fs which is incompatible with
50+
# the version shipped by e2fsprogs. To prevent a name clash we install
51+
# androids version of mke2fs under a different name. This name can be
52+
# configured here.
53+
#
54+
# See also: https://bugs.archlinux.org/task/56955
55+
android_mke2fs_name = 'mke2fs.android'
56+
57+
if host_machine.system() == 'darwin'
58+
add_project_arguments(
59+
'-D_DARWIN_C_SOURCE', '-D__DARWIN_C_LEVEL=__DARWIN_C_FULL',
60+
language: ['c', 'cpp']
61+
)
62+
endif
63+
64+
CXX = meson.get_compiler('cpp')
65+
CC = meson.get_compiler('c')
66+
foreach comp_data: [['c', CC], ['cpp', CXX]]
67+
lang = comp_data[0]
68+
comp = comp_data[1]
69+
70+
if comp.has_argument('-ftrivial-auto-var-init=zero')
71+
add_project_arguments('-ftrivial-auto-var-init=zero', language: lang)
72+
else
73+
if comp.has_multi_arguments(
74+
'-ftrivial-auto-var-init=zero',
75+
'-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang'
76+
)
77+
add_project_arguments(
78+
'-ftrivial-auto-var-init=zero',
79+
'-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang',
80+
language: lang
81+
)
82+
endif
83+
endif
84+
endforeach
85+
86+
# Android seems to use various attributes supported by clang but not by
87+
# GCC which causes it to emit lots of warnings. Since these attributes
88+
# don't seem to effect runtime behaviour simply disable the warnings.
89+
foreach lang: ['c', 'cpp']
90+
if meson.get_compiler(lang).get_argument_syntax() == 'gcc'
91+
add_project_arguments('-Wno-attributes', language: lang)
92+
endif
93+
endforeach
94+
95+
# libfsmgr (required by fastboot) requires a 64-bit off_t for lseek. On
96+
# 32-bit glibc platforms this is not the case by default.
97+
add_global_arguments(
98+
'-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE64_SOURCE',
99+
language: ['c', 'cpp']
100+
)
101+
102+
version_header = files('version.h.in')
103+
subdir('meson')
104+
version_header_inc = include_directories('meson')
105+
106+
subdir('vendor')
107+
108+
subdir('completions')
109+
110+
if get_option('generate_sbom_data')
111+
nmeum_patches = []
112+
foreach dirname, patchlist: nmeum_submodule_patches
113+
foreach patch: patchlist
114+
nmeum_patches += dirname / patch
115+
endforeach
116+
endforeach
117+
118+
added_patches = []
119+
foreach dirname, patchlist: added_submodule_patches
120+
foreach patch: patchlist
121+
added_patches += dirname / patch
122+
endforeach
123+
endforeach
124+
125+
configure_file(
126+
command: [
127+
'SBOM_scripts/save_args.py',
128+
'@OUTPUT@',
129+
nmeum_patches
130+
],
131+
install_dir: get_option('licensedir'),
132+
output: 'nmeum_patches.bin',
133+
)
134+
135+
configure_file(
136+
command: [
137+
'SBOM_scripts/save_args.py',
138+
'@OUTPUT@',
139+
added_patches
140+
],
141+
install_dir: get_option('licensedir'),
142+
output: 'added_patches.bin',
143+
)
144+
endif

meson/build/meson.build

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2025 meator
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
vendor_cfg = configuration_data()
16+
17+
# Vendor string used in version outputs.
18+
vendor_cfg.set('ANDROID_VENDOR', 'android-tools-static')
19+
20+
configure_file(
21+
input: version_header,
22+
output: 'version.h',
23+
configuration: vendor_cfg,
24+
format: 'cmake@',
25+
)

meson/meson.build

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2025 meator
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
version_cfg = configuration_data()
16+
17+
# Vendor string used in version outputs.
18+
version_cfg.set('ANDROID_VERSION', meson.project_version())
19+
20+
configure_file(
21+
input: '../platform_tools_version.h.in',
22+
output: 'platform_tools_version.h',
23+
configuration: version_cfg,
24+
format: 'cmake@',
25+
)
26+
27+
subdir('build')

meson_options.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2025 meator
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
option(
16+
'use_bundled_libusb',
17+
type: 'boolean',
18+
value: false,
19+
description: 'Use bundled Google libusb. A wrap or a system dependency ' +
20+
'are used if set to false.'
21+
)
22+
option(
23+
'libusb_enable_udev',
24+
type: 'feature',
25+
description: 'Enable udev for device enumeration and hotplug support ' +
26+
'(recommended); only relevant on Linux, other OSes ignore this option'
27+
)
28+
option(
29+
'generate_manpages',
30+
type: 'feature',
31+
description: 'Generate manpages (currently for adb only, more might be ' +
32+
'added in the future). Requires pandoc executable.'
33+
)

onlypatch.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
This is used in the GitHub Actions runner. See the commend above this
2+
change for more info.
3+
--- a/vendor/meson.build
4+
+++ b/vendor/meson.build
5+
@@ -132,7 +132,7 @@ endif
6+
# Actions runner. It is padded by comments to produce a nice independent patch
7+
# with the context lines containing only comments.
8+
9+
-#subdir_done()
10+
+subdir_done()
11+
12+
# See above.
13+
# See above.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
From 0d31b973954191e188732182617a0fca72cf7a2a Mon Sep 17 00:00:00 2001
2+
From: meator <meator.dev@gmail.com>
3+
Date: Tue, 26 Aug 2025 21:45:59 +0200
4+
Subject: [PATCH] Add support for Meson Wrap libusb include
5+
6+
This is a modification of
7+
0005-Include-libusb-1.0-libusb.h-instead-of-libusb-libusb.patch made by
8+
android-tools-static.
9+
---
10+
client/usb_libusb.cpp | 5 ++++-
11+
1 file changed, 4 insertions(+), 1 deletion(-)
12+
13+
diff --git a/client/usb_libusb.cpp b/client/usb_libusb.cpp
14+
index f533b55..6edd3ce 100644
15+
--- a/client/usb_libusb.cpp
16+
+++ b/client/usb_libusb.cpp
17+
@@ -39,7 +39,10 @@
18+
#ifdef ANDROID_TOOLS_USE_BUNDLED_LIBUSB
19+
#include <libusb/libusb.h>
20+
#else
21+
-#include <libusb-1.0/libusb.h>
22+
+// nmeum/android-tools includes libusb-1.0/libusb.h instead. I don't know why.
23+
+// libusb's pkg-config file adds libusb-1.0 to include directories, so let's
24+
+// include the header directly
25+
+#include <libusb.h>
26+
#endif
27+
28+
#include <android-base/file.h>
29+
--
30+
2.51.0
31+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
From a83ae058b148ac8a62ea32584c51728617d82b8b Mon Sep 17 00:00:00 2001
2+
From: meator <meator.dev@gmail.com>
3+
Date: Sun, 6 Jul 2025 14:34:31 +0200
4+
Subject: [PATCH] WIN: fix compilation
5+
6+
Source:
7+
https://github.com/msys2/MINGW-packages/blob/b2c2452bcf764dc5c58c3cdf596d24d792c0dff7/mingw-w64-android-tools/0003-fix-building-with-gcc-mingw.patch
8+
---
9+
sysdeps.h | 2 ++
10+
1 file changed, 2 insertions(+)
11+
12+
diff --git a/sysdeps.h b/sysdeps.h
13+
index 99f6b74..7bf5b99 100644
14+
--- a/sysdeps.h
15+
+++ b/sysdeps.h
16+
@@ -141,8 +141,10 @@ static inline int unix_read(borrowed_fd fd, void* buf, size_t len) {
17+
static inline int unix_write(borrowed_fd fd, const void* buf, size_t len) {
18+
return write(fd.get(), buf, len);
19+
}
20+
+#ifdef write
21+
#undef write
22+
#define write ___xxx_write
23+
+#endif
24+
25+
#undef pwrite
26+
#define pwrite ___xxx_pwrite
27+
--
28+
2.50.0
29+

0 commit comments

Comments
 (0)