Skip to content

Commit 575cd6a

Browse files
CaslynCQ Bot
authored andcommitted
[ulib][c] Begin soft migration of files to /strings
llvm/llvm-project#118899 began the process of moving files from /string to /strings. This CL likewise introduces the /strings directory to Fuchsia's build machinery and performs the first step in migrating the needed targets to /strings. Since it's expected that we'll need to repeat this process as more targets are migrated to strings/ in the future, this CL introduces a (temporary) exec_script that can be used as an example for future CL migrations, to make it easier and faster to detect file changes (but note the exec_script gets cleaned up after each migration, as is done in Ia8de544a2695125f888544071b08f37906fe381d). Bug: 383347626 Change-Id: I81b66e1f5ec01f240ed8cf1f601764eb89ed6cff Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1172248 Reviewed-by: David Fang <[email protected]> Commit-Queue: Auto-Submit <[email protected]> Fuchsia-Auto-Submit: Caslyn Tonelli <[email protected]>
1 parent c00b2af commit 575cd6a

File tree

6 files changed

+114
-23
lines changed

6 files changed

+114
-23
lines changed

.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ exec_script_whitelist = [
4747
"//build/toolchain/default_concurrent_jobs.gni",
4848
"//build/toolchain/zircon/zircon_toolchain.gni",
4949
"//zircon/kernel/arch/x86/phys/BUILD.gn",
50+
51+
# TODO(https://fxbug.dev/383347626): This is temporary to perform soft-migration.
52+
"//zircon/system/ulib/c/string/file_exists_check.gni",
5053
]
5154

5255
check_system_includes = true

zircon/system/ulib/c/BUILD.gn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import("//build/toolchain/ifs_shared_library.gni")
1111
import("//build/zircon/migrated_targets.gni")
1212
import("libc.gni")
1313
import("libc_toolchain.gni")
14+
import("string/file_exists_check.gni")
1415

1516
assert(libc == get_path_info(get_path_info(".", "abspath"), "dir"),
1617
get_path_info(get_path_info(".", "abspath"), "dir"))
@@ -34,8 +35,14 @@ libc_testonly_components = []
3435

3536
if (use_llvm_libc_string_functions) {
3637
libc_components += [ "string" ]
38+
if (!file_exists_in_string) {
39+
libc_components += [ "strings" ]
40+
}
3741
} else {
3842
libc_testonly_components += [ "string" ]
43+
if (!file_exists_in_string) {
44+
libc_testonly_components += [ "strings" ]
45+
}
3946
}
4047

4148
group("components") {

zircon/system/ulib/c/string/BUILD.gn

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
# found in the LICENSE file.
44

55
import("../libc.gni")
6+
import("file_exists_check.gni")
67

78
llvm_libc_group("string") {
89
deps = [
9-
":compat",
1010
":mem",
1111
":str",
1212
]
1313

14+
# TODO(https://fxbug.dev/383347626): these files are moved from string/ to
15+
# strings/ after llvm rev 431ea2d076f8a5ca35b2c293dd5d62f5ce083f45
16+
if (file_exists_in_string) {
17+
deps += [ ":compat" ]
18+
}
19+
1420
# TODO(https://fxbug.dev/42053650): not yet using the llvm-libc versions of these
1521
non_test_deps = [
1622
"//zircon/third_party/ulib/musl/src/string:strerror_r",
@@ -176,12 +182,10 @@ llvm_libc_source_set("minimal-str") {
176182

177183
llvm_libc_source_set("str") {
178184
functions = [
179-
"strcasecmp",
180185
"strcasestr",
181186
"strcoll",
182187
"strxfrm",
183188
"strdup",
184-
"strncasecmp",
185189
"strndup",
186190
"strtok",
187191
"strtok_r",
@@ -193,6 +197,15 @@ llvm_libc_source_set("str") {
193197
]
194198

195199
deps = [ ":minimal-str" ]
200+
201+
# TODO(https://fxbug.dev/383347626): these files are moved from string/ to
202+
# strings/ after llvm rev 431ea2d076f8a5ca35b2c293dd5d62f5ce083f45
203+
if (file_exists_in_string) {
204+
functions += [
205+
"strncasecmp",
206+
"strcasecmp",
207+
]
208+
}
196209
}
197210

198211
llvm_libc_source_set("strsignalerror") {
@@ -239,32 +252,36 @@ llvm_libc_source_set("StringUtil") {
239252
]
240253
}
241254

242-
llvm_libc_source_set("compat") {
243-
functions = [
244-
"bcmp",
245-
"bcopy",
246-
"bzero",
247-
"index",
248-
"rindex",
249-
]
250-
251-
deps = [ ":swab" ]
252-
}
255+
if (file_exists_in_string) {
256+
llvm_libc_source_set("compat") {
257+
functions = [
258+
"bcmp",
259+
"bcopy",
260+
"bzero",
261+
"index",
262+
"rindex",
263+
]
264+
265+
deps = [ ":swab" ]
266+
}
253267

254-
# This lives in libc/src/unistd upstream because it's declared in <unistd.h>
255-
# but it's really a compat string function, so we include it here instead.
256-
llvm_libc_source_set("swab") {
257-
dir = "unistd"
258-
functions = [ "swab" ]
268+
# This lives in libc/src/unistd upstream because it's declared in <unistd.h>
269+
# but it's really a compat string function, so we include it here instead.
270+
llvm_libc_source_set("swab") {
271+
dir = "unistd"
272+
functions = [ "swab" ]
273+
}
259274
}
260275

261276
# This provides an archive library of the universally safe string functions.
262277
# When built outside the "user.libc" environment, these always define only
263278
# hidden-visibility symbols and should be safe in any build environment.
264279
static_library("hermetic") {
265280
complete_static_lib = true
266-
deps = [
267-
":compat",
268-
":minimal-str",
269-
]
281+
deps = [ ":minimal-str" ]
282+
if (file_exists_in_string) {
283+
deps += [ ":compat" ]
284+
} else {
285+
deps += [ "//zircon/system/ulib/c/strings:compat" ]
286+
}
270287
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#! /bin/sh
2+
# Copyright 2024 The Fuchsia Authors. All rights reserved.
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
6+
# This script prints "true" if the file exists, else "false".
7+
8+
file="$1"
9+
if test -f "$file"; then
10+
echo "true"
11+
else
12+
echo "false"
13+
fi
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2024 The Fuchsia Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
# TODO(https://fxbug.dev/383347626): soft-migration of source file location
6+
# changes. This exec_script is temporary, used only during this migration.
7+
file = "//third_party/llvm-libc/src/src/string/bcmp.cpp"
8+
file_exists_in_string = exec_script("file_exists.sh",
9+
[ rebase_path("$file", root_build_dir) ],
10+
"value")

zircon/system/ulib/c/strings/BUILD.gn

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2024 The Fuchsia Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
import("../libc.gni")
6+
import("../string/file_exists_check.gni")
7+
8+
if (!file_exists_in_string) {
9+
llvm_libc_group("strings") {
10+
deps = [
11+
":compat",
12+
":str",
13+
]
14+
}
15+
16+
llvm_libc_source_set("str") {
17+
functions = [
18+
"strcasecmp",
19+
"strncasecmp",
20+
]
21+
}
22+
23+
llvm_libc_source_set("compat") {
24+
functions = [
25+
"bcmp",
26+
"bcopy",
27+
"bzero",
28+
"index",
29+
"rindex",
30+
]
31+
32+
deps = [ ":swab" ]
33+
}
34+
35+
# This lives in libc/src/unistd upstream because it's declared in <unistd.h>
36+
# but it's really a compat string function, so we include it here instead.
37+
llvm_libc_source_set("swab") {
38+
dir = "unistd"
39+
functions = [ "swab" ]
40+
}
41+
}

0 commit comments

Comments
 (0)