Skip to content

fix(cmake): make dash_static find libedit headers on Linux#8

Open
lcolok wants to merge 1 commit intoxicilion:masterfrom
lcolok:fix/linux-cmake-libedit-include
Open

fix(cmake): make dash_static find libedit headers on Linux#8
lcolok wants to merge 1 commit intoxicilion:masterfrom
lcolok:fix/linux-cmake-libedit-include

Conversation

@lcolok
Copy link
Copy Markdown

@lcolok lcolok commented Apr 18, 2026

Summary

On Linux, a clean cmake -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build against master (72bc8c2, v2.1.0) fails to compile dash_static:

/home/logic/boxsh/third_party/dash-0.5.12/src/myhistedit.h:34:10:
fatal error: histedit.h: No such file or directory
   34 | #include <histedit.h>
      |          ^~~~~~~~~~~~
compilation terminated.

Root cause

CMakeLists.txt wires dash_static's include dirs at line 73:

target_include_directories(dash_static
    PUBLIC
        ${DASH_SRC_DIR}
        ${DASH_ROOT}
)

But LIBEDIT_INSTALL_DIR (where libedit's histedit.h lands after libedit_vendored builds) is only defined at line 116, so dash_static has no visibility into libedit's headers. On top of that, dash_static has no explicit dependency on libedit_vendored, so CMake is free to start compiling dash sources before libedit's headers are installed.

Linux reproduces this because the dash build unconditionally requires histedit.h. macOS happens to resolve the header through another search path, which is why the regression was not caught there.

Fix

Three small, additive changes to CMakeLists.txt:

  1. Move set(LIBEDIT_INSTALL_DIR ${CMAKE_BINARY_DIR}/libedit-prefix) before add_library(dash_static), so the variable is defined before it is used.
  2. Add ${LIBEDIT_INSTALL_DIR}/include to target_include_directories(dash_static) so #include <histedit.h> resolves.
  3. Add add_dependencies(dash_static libedit_vendored) so the external libedit build (which installs histedit.h into that include dir) completes before dash_static compilation starts.

Diff is 4 lines, no logic changed elsewhere.

Verification

Tested on Ubuntu 24.04 LTS (x86_64):

With the patch — clean Release build succeeds:

$ rm -rf build && cmake -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build -j8
...
[100%] Linking CXX executable boxsh
[100%] Built target boxsh
-rwxrwxr-x 1 logic logic 1.6M build/boxsh

Basic smoke tests all pass:

Check Result
boxsh --version boxsh version 2.1.0
boxsh -c 'echo hi' hi
boxsh --sandbox -c 'cat /proc/1/comm' boxsh (PID namespace active)
boxsh --sandbox --new-net-ns -c 'ping -c1 -W1 8.8.8.8' Network is unreachable
--bind cow:SRC:DST writes isolated from SRC confirmed

Reverse verification — stashing the patch reliably reproduces the failure:

$ git stash
$ rm -rf build && cmake -B build -DCMAKE_BUILD_TYPE=Release
$ cmake --build build -j8 2>&1 | grep -E 'error|histedit'
/home/logic/boxsh/third_party/dash-0.5.12/src/myhistedit.h:34:10:
fatal error: histedit.h: No such file or directory

Risk

Low. The change only reorders a CMake variable definition and adds one include path plus one add_dependencies edge for a target that already depends on libedit at link time via boxsh. No runtime behavior changes.

dash_static's target_include_directories references LIBEDIT_INSTALL_DIR
before the variable is defined further down in the file, so the include
path effectively becomes `/include` and compilation of any dash source
that includes `myhistedit.h` (which transitively `#include <histedit.h>`)
fails on Linux with:

    fatal error: histedit.h: No such file or directory

Linux is affected because the dash build requires `histedit.h` at compile
time. On macOS the same translation units still resolve the header
through other search paths, which is why this regression was not caught
on that platform.

The fix has three minimal parts:

1. Move `set(LIBEDIT_INSTALL_DIR ...)` above `add_library(dash_static)`
   so the variable is defined before it is referenced.
2. Add `${LIBEDIT_INSTALL_DIR}/include` to dash_static's include dirs.
3. Add `add_dependencies(dash_static libedit_vendored)` so the libedit
   external project is built (and its headers installed) before
   dash_static is compiled.

Verified by:
- Clean Release build on Ubuntu 24.04 (x86_64) now succeeds and
  produces a working `build/boxsh`.
- Reverting just the three added lines reliably reproduces the
  `histedit.h: No such file or directory` failure during dash_static
  compilation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant