Skip to content

Commit f934dd7

Browse files
committed
Add musl_libc toggle, regenerate ld.so.cache within the initrd
Signed-off-by: Zen <[email protected]>
1 parent 5539135 commit f934dd7

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

docs/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Modules write to a shared config dict that is accessible by other modules.
4343
* `build_logging` (false) Enables additional logging during the build process.
4444
* `make_nodes` (false) Create real device nodes in the build dir.
4545
* `find_libgcc` (true) Automatically locates libgcc using ldconfig -p and adds it to the initramfs.
46+
* `musl_libc` (false) Disable ldconfig -p usage for libgcc detection, skip ld.so.cache regeneration.
4647
* `out_dir` (initramfs_out) If relative, it will be placed under `tmpdir`, defines the output directory.
4748
* `out_file` Sets the name of the output file, under `out_dir`.
4849
* `clean` (true) forces the build dir to be cleaned on each run.

src/ugrd/base/core.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "desultory"
2-
__version__ = "4.5.1"
2+
__version__ = "4.6.0"
33

44
from os import environ, makedev, mknod, uname
55
from pathlib import Path
@@ -303,6 +303,7 @@ def deploy_nodes(self) -> None:
303303
raise e
304304

305305

306+
@unset("musl_libc", "Skipping libgcc_s dependency resolution, musl_libc is enabled.", log_level=20)
306307
@contains("find_libgcc", "Skipping libgcc_s dependency resolution", log_level=20)
307308
def autodetect_libgcc(self) -> None:
308309
"""Finds libgcc.so, adds a 'dependencies' item for it.
@@ -318,7 +319,9 @@ def autodetect_libgcc(self) -> None:
318319
musl_warning = True
319320

320321
if musl_warning:
321-
self.logger.warning("This check can be disabled by setting `find_libgcc = false` in the configuration.")
322+
self.logger.warning(
323+
"This check can be disabled by setting `musl_libc = true` or `find_libgcc = false` in the configuration."
324+
)
322325
return self.logger.warning("Unable to run ldconfig -p, if glibc is being used, this is fatal!")
323326

324327
if cmd.returncode != 0:
@@ -343,6 +346,17 @@ def autodetect_musl(self) -> None:
343346
if musl_path.exists():
344347
self.logger.info("Detected musl search path: %s" % c_(musl_path, "cyan"))
345348
self["dependencies"] = musl_path
349+
elif self["musl_libc"]:
350+
raise AutodetectError("Musl libc is enabled, but the musl search path was not found: %s" % musl_path)
351+
352+
353+
@unset("musl_libc", "Skipping ld.so.cache regeneration, musl_libc is enabled.", log_level=30)
354+
def regen_ld_so_cache(self) -> None:
355+
"""Regenerates the ld.so.cache file in the build dir"""
356+
self.logger.info("Regenerating ld.so.cache")
357+
build_path = self._get_build_path("/")
358+
self._run(["ldconfig", "-r", str(build_path)])
359+
self["check_included_or_mounted"] = "etc/ld.so.cache"
346360

347361

348362
def _process_out_file(self, out_file: str) -> None:

src/ugrd/base/core.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ timeout = 15
5050
"deploy_symlinks",
5151
"deploy_nodes"]
5252

53+
[imports.build_final]
54+
"ugrd.base.core" = [ "regen_ld_so_cache" ]
55+
5356
[custom_parameters]
5457
hostonly = "bool" # If true, the initramfs will be built specifically for the host building it
5558
validate = "bool" # If true, the configuration of the initramfs will be validated against the host
@@ -70,6 +73,7 @@ zstd_dependencies = "NoDupFlatList" # ZStandard compressed dependencies propert
7073
gz_dependencies = "NoDupFlatList" # GZipped dependencies property, used to define the gzipped dependencies (will be extracted)
7174
library_paths = "NoDupFlatList" # library_paths property, used to define the library paths to add to LD_LIBRARY_PATH
7275
find_libgcc = "bool" # If true, the initramfs will search for libgcc_s.so.1 and add it to the initramfs
76+
musl_libc = "bool" # If true, disables find_libgcc and regen_ld_so_cache
7377
libraries = "NoDupFlatList" # Additional libraries, by name, added to the initramfs
7478
binaries = "NoDupFlatList" # Binaries which should be included in the intiramfs, dependencies resolved with lddtree
7579
binary_search_paths = "NoDupFlatList" # Binary paths, used to define the paths to search for binaries

0 commit comments

Comments
 (0)