Skip to content

shebang: changed scripts shebang to better support systems like bsd and nixos#306

Closed
lromor wants to merge 1 commit intobazelbuild:mainfrom
lromor:fix-portable-shebang
Closed

shebang: changed scripts shebang to better support systems like bsd and nixos#306
lromor wants to merge 1 commit intobazelbuild:mainfrom
lromor:fix-portable-shebang

Conversation

@lromor
Copy link
Contributor

@lromor lromor commented Jan 16, 2025

The assumption that bash is always located at /bin/bash does not always hold true.
In POSIX systems, it is recommended to avoid relying on common paths. Instead, one should either:

  • Hardcode the full absolute path to the executable, or
  • Locate the command in the PATH.

A more portable approach is to use #!/usr/bin/env bash, which resolves binaries through the PATH.

This patch updates the default shebang string in this repository to improve portability on systems like NixOS or BSD.

@hzeller
Copy link

hzeller commented Jan 16, 2025

Nice! This will unbreak systems that behave Posix-correctly and don't have bash in /bin.

@lromor lromor force-pushed the fix-portable-shebang branch from 4d6035a to 5b11bac Compare February 12, 2025 18:06
@lromor lromor force-pushed the fix-portable-shebang branch from 5b11bac to f4841a4 Compare February 12, 2025 18:10
@hzeller
Copy link

hzeller commented Feb 20, 2025

What is the review-status here ? This will make life on NixOS much easier.

hzeller added a commit to hzeller/fpga-assembler that referenced this pull request Mar 18, 2025
bazelbuild/rules_cc#306 has been merged, so we
can use unstable from upstream now.

Also, upgrade to latest bant version.
lromor pushed a commit to lromor/fpga-assembler that referenced this pull request Mar 18, 2025
bazelbuild/rules_cc#306 has been merged, so we
can use unstable from upstream now.

Also, upgrade to latest bant version.
@hzeller hzeller mentioned this pull request Mar 26, 2025
13 tasks
hzeller added a commit to hzeller/OpenROAD that referenced this pull request Apr 10, 2025
When running the compilation on NixOS, it is not possible currently
to use the llvm_toolchain mentioned in the MODULE.bazel, but necessary
to run the local toolchain (`clangStdenv`). That in turn is strict and
only allows to compile C files when invoked with `clang` and
requires `clang++` or `clang -xc++` to compile C++ files - unlike a typical clang
installation that attempts to auto-detect. But Bazel is lazy and
invokes c++ compilation with `clang` ...

Another issue: the latest rules_cc version has hardcoded paths to
`/bin/bash` while the correct way to use that on Posix systems is to
call it via `/usr/bin/env`.

So, this PR solves both these issues:

  * Add `-xc++` to the compiler invocation for cxx compilation.

  * Use a rules_cc that has the fix to use /usr/bin/env
    (bazelbuild/rules_cc#306), but that
    is not released yet on BCR (once 0.1.2 is out we can probably
    use that directly).

Signed-off-by: Henner Zeller <hzeller@google.com>
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.

3 participants