Skip to content

Commit b703b42

Browse files
authored
Fix how we locate Clang runtime library directory (#182)
Also add a branch.txt file and logic in build_and_release.sh to use it, as specified in https://github.com/yugabyte/yugabyte-db-thirdparty#setting-up-a-new-release-version-branch
1 parent 43f3f7a commit b703b42

File tree

5 files changed

+71
-12
lines changed

5 files changed

+71
-12
lines changed

branch.txt

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

build_and_release.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,17 @@ fi
155155

156156
original_repo_dir=$PWD
157157
git_sha1=$( git rev-parse HEAD )
158-
tag=v$( date +%Y%m%d%H%M%S )-${git_sha1:0:10}
158+
159+
branch_file_path="$YB_THIRDPARTY_DIR/branch.txt"
160+
branch_name=""
161+
if [[ -f ${branch_file_path} ]]; then
162+
branch_name=$(<"${branch_file_path}")
163+
fi
164+
tag=v
165+
if [[ -n ${branch_name} ]]; then
166+
tag+="${branch_name}-"
167+
fi
168+
tag+=$( date +%Y%m%d%H%M%S )-${git_sha1:0:10}
159169

160170
archive_dir_name=yugabyte-db-thirdparty-$tag
161171
if [[ -z ${YB_THIRDPARTY_ARCHIVE_NAME_SUFFIX:-} ]]; then

python/yugabyte_db_thirdparty/builder.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -985,13 +985,21 @@ def init_linux_clang_flags(self, dep: Dependency) -> None:
985985
# parts of the runtime library and C++ standard libraries are present.
986986

987987
assert self.compiler_choice.cc is not None
988-
compiler_rt_lib_dir = get_clang_library_dir(self.compiler_choice.get_c_compiler())
989-
self.add_lib_dir_and_rpath(compiler_rt_lib_dir)
990988
ubsan_lib_candidates = []
991989
ubsan_lib_found = False
992990
for ubsan_lib_arch_suffix in ['', f'-{platform.processor()}']:
993991
ubsan_lib_name = f'clang_rt.ubsan_minimal{ubsan_lib_arch_suffix}'
994-
ubsan_lib_so_path = os.path.join(compiler_rt_lib_dir, f'lib{ubsan_lib_name}.so')
992+
ubsan_lib_file_name = f'lib{ubsan_lib_name}.so'
993+
compiler_rt_lib_dir_as_list = get_clang_library_dir(
994+
self.compiler_choice.get_c_compiler(),
995+
look_for_file=ubsan_lib_file_name)
996+
if not compiler_rt_lib_dir_as_list:
997+
continue
998+
assert len(compiler_rt_lib_dir_as_list) == 1
999+
compiler_rt_lib_dir = compiler_rt_lib_dir_as_list[0]
1000+
self.add_lib_dir_and_rpath(compiler_rt_lib_dir)
1001+
1002+
ubsan_lib_so_path = os.path.join(compiler_rt_lib_dir, ubsan_lib_file_name)
9951003
ubsan_lib_candidates.append(ubsan_lib_so_path)
9961004
if os.path.exists(ubsan_lib_so_path):
9971005
self.ld_flags.append(f'-l{ubsan_lib_name}')

python/yugabyte_db_thirdparty/clang_util.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,63 @@ def get_clang_library_dirs(clang_executable_path: str) -> List[str]:
3939
return library_dirs
4040

4141

42-
def get_clang_library_dir(clang_executable_path: str) -> str:
42+
def get_clang_library_dir(
43+
clang_executable_path: str,
44+
look_for_file: Optional[str] = None,
45+
all_dirs: bool = False) -> List[str]:
46+
"""
47+
Finds and returns the Clang runtime library directory using the provided Clang executable path.
48+
For each of the library directories returned by get_clang_library_dirs(), we will look for a
49+
a lib/linux or lib/<arch>-unknown-linux-gnu subdirectory. If we find such a subdirectory, we
50+
will consider returning it (but only if it contains the given file if specified).
51+
52+
:param clang_executable_path: The path to the Clang executable.
53+
:param look_for_file: An optional file to look for in the candidate directory. If this file does
54+
not exist in the candidate directory, we will continue looking for another
55+
candidate directory.
56+
:param all_dirs: to return all possible directories. This set of directories is filtered by the
57+
presence of the look_for_file if specified.
58+
:return: the Clang runtime library directory, or an empty list if not found, or all directories
59+
if all_dirs is specified.
60+
"""
4361
library_dirs = get_clang_library_dirs(clang_executable_path)
4462
candidate_dirs: List[str] = []
4563

4664
arch = platform.machine()
4765
arch_specific_subdir_name = f'{arch}-unknown-linux-gnu'
66+
subdir_names = ['linux', arch_specific_subdir_name]
67+
68+
found_dirs: List[str] = []
4869

4970
for library_dir in library_dirs:
50-
for subdir_name in ['linux', arch_specific_subdir_name]:
71+
for subdir_name in subdir_names:
5172
candidate_dir = os.path.join(library_dir, 'lib', subdir_name)
52-
if os.path.isdir(candidate_dir):
53-
return candidate_dir
73+
if os.path.isdir(candidate_dir) and (
74+
look_for_file is None or
75+
os.path.exists(os.path.join(candidate_dir, look_for_file))):
76+
if all_dirs:
77+
found_dirs.append(candidate_dir)
78+
else:
79+
# Return the first directory we found satisfying the condition.
80+
return [candidate_dir]
5481
candidate_dirs.append(candidate_dir)
5582

83+
if (all_dirs and found_dirs) or look_for_file is not None:
84+
# If we are looking for all directories, return all directories we found. But make sure
85+
# we found at least one.
86+
#
87+
# If we are looking for a specific file, allow returning an empty list if we did not find
88+
# a directory with that particular file.
89+
return found_dirs
90+
5691
for candidate_dir in candidate_dirs:
5792
log(f"Considered candidate directory: {candidate_dir}")
5893
raise ValueError(
5994
"Could not find the Clang runtime library directory by appending lib/... suffixes to "
6095
"any of the directories returned by 'clang -print-search-dirs' "
61-
f"(clang path: {clang_executable_path}): {library_dirs}")
96+
f"(clang path: {clang_executable_path}, subdir names: {subdir_names}, "
97+
f"file name that must exist in the directory: {look_for_file}): {library_dirs}"
98+
)
6299

63100

64101
def get_clang_include_dir(clang_executable_path: str) -> str:

python/yugabyte_db_thirdparty/yb_build_thirdparty_main.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@ def main() -> None:
7272
lib_tester = get_lib_tester(fs_layout=builder.fs_layout)
7373
lib_tester.add_allowed_shared_lib_paths(builder.additional_allowed_shared_lib_paths)
7474
if builder.compiler_choice.is_linux_clang():
75-
lib_tester.add_allowed_shared_lib_paths({
76-
get_clang_library_dir(builder.compiler_choice.get_c_compiler())
77-
})
75+
clang_library_dirs: List[str] = get_clang_library_dir(
76+
builder.compiler_choice.get_c_compiler(),
77+
all_dirs=True
78+
)
79+
assert len(clang_library_dirs) > 0
80+
lib_tester.add_allowed_shared_lib_paths(set(clang_library_dirs))
7881
lib_tester.configure_for_compiler(builder.compiler_choice)
7982

8083
lib_tester.run()

0 commit comments

Comments
 (0)