Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate tiny compiled binary for wrapping executables #124556

Merged
merged 49 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
5edd17c
Add bergkvist to maintainer list
bergkvist May 26, 2021
de1f53b
Add make-c-wrapper.sh for creating binary executable wrappers
bergkvist May 26, 2021
eef4fa8
make-c-wrapper: Fix typo in generated code documentation
bergkvist May 26, 2021
131ed20
make-c-wrapper: Remove trailing whitespace (editorconfig)
bergkvist May 26, 2021
e8cedf3
make-c-wrapper: Fix typo in generated documentation
bergkvist May 27, 2021
8d2964a
Rename make-c-wrapper.sh to make-binary-wrapper.sh. Refactor to match…
bergkvist May 31, 2021
1d64281
Remove line at the bottom of make-binary-wrapper that executes makeBi…
bergkvist May 31, 2021
dcba417
Add support for --add-flags, --prefix and --suffix
bergkvist Aug 23, 2021
b58c857
Switch to using strlen in concat3Fn. Make sure uses-variables are loc…
bergkvist Aug 26, 2021
b62216a
Fix shellcheck warnings. Use single quotes for printf format strings.…
bergkvist Oct 1, 2021
ac99a6f
Add makeBinaryWrapper to pkgs/top-level/all-packages.nix
bergkvist Oct 1, 2021
d930fec
Return an #error macro if the wrong number of arguments are supplied
bergkvist Oct 1, 2021
3df841b
Make error messages more consistent
bergkvist Oct 1, 2021
adef70c
Specify uses_prefix, uses_suffix and uses_concat3 as local vars. Make…
bergkvist Oct 4, 2021
b7d36b8
Add golden tests for make-binary-wrapper.
bergkvist Oct 4, 2021
4b833cc
EditorConfig: Switch from tabs to spaces
bergkvist Oct 4, 2021
a45c5db
makeBinaryWrapper: Assert $1 is executable
doronbehar Oct 1, 2021
c310cb0
makeBinaryWrapper: add wrapProgramBinary (like wrapProgram)
doronbehar Oct 1, 2021
ba86a19
makeBinaryWrapper: Document
doronbehar Oct 1, 2021
1218b82
Move assertExecutable from makeCWrapper to makeBinaryWrapper to ensur…
bergkvist Oct 19, 2021
6517e5b
Improve explenations for wrap*Program
doronbehar Oct 19, 2021
7cca19a
Set strictDeps = true in makeGoldenTest
bergkvist Oct 19, 2021
a95a7a2
Switch from buildInputs to nativeBuildInpuits in makeGoldenTest
bergkvist Oct 19, 2021
eb048d8
Rephrase makeWrapper setup-hook
doronbehar Oct 20, 2021
3a014be
Assert that malloc does not return a NULL pointer for better error me…
bergkvist Nov 9, 2021
4e55d34
Add assertValidEnvName and check that variable name is valid during c…
bergkvist Dec 1, 2021
97d62a9
Switch from exit(1) to abort() in assert_success
bergkvist Dec 1, 2021
3997e9d
Switch from malloc to calloc in addFlags
bergkvist Dec 1, 2021
a1e6226
Replace concat3 with asprintf in set_env_prefix and set_env_suffix.
bergkvist Dec 1, 2021
e3c94f3
Use cc instead of gcc in makeBinaryWrapper
bergkvist Dec 2, 2021
a47286f
Add argument --inherit-argv0 to replace use case `--argv0 '$0'`. Fix …
bergkvist Dec 2, 2021
64da827
Add new argument: --chdir DIR (alternative to --run "cd DIR" in makeW…
bergkvist Dec 2, 2021
d8375fb
Add tests for `--inherit-argv0` and `--chdir DIR`
bergkvist Dec 2, 2021
2b103ab
Remove TODO in documentation
doronbehar Dec 2, 2021
2b5a2d4
Switch to embedding input arguments instead of generated C code in bi…
bergkvist Dec 7, 2021
7cf1aa1
Separate out indentation responsibility to indent4 in makeCWrapper us…
bergkvist Dec 7, 2021
f3b16a6
Fix typo in make-binary-wrapper
tfc Dec 8, 2021
32d566e
wrapProgramBinary -> binaryWrapProgram
doronbehar Dec 8, 2021
2bc7345
Add golden effects test
tfc Dec 7, 2021
e7c70ce
Inject gcc path into makewrapper script
Dec 9, 2021
177f0a6
make makeWrapper and makeBinaryWrapper drop-in-replaceable
tfc Dec 9, 2021
df13841
Merge branch 'bergkvist/make-c-wrapper' into make-c-wrapper
bergkvist Dec 9, 2021
c42e674
Rephrase documentation for both makeWrapper implementations
doronbehar Dec 9, 2021
b7e00ed
make-binary-wrapper: Add -Wall -Werror -Wpedantic
tfc Dec 9, 2021
87fcb7b
make-binary-wrapper: Add -euo pipefail to bash script
tfc Dec 9, 2021
d5e028a
make-binary-wrapper: Make CC substitution safer
tfc Dec 9, 2021
bdaa0e2
make-binary-wrapper: Add sanitizer default option
tfc Dec 9, 2021
ceffea6
Small rephrase of wrapProgram documentation
doronbehar Dec 9, 2021
39b0aa4
Change default cc from gcc to stdenv.cc.cc to reduce closure size on …
bergkvist Dec 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions doc/stdenv/stdenv.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ The standard environment provides a number of useful functions.

### `makeWrapper` \<executable\> \<wrapperfile\> \<args\> {#fun-makeWrapper}

Constructs a wrapper for a program with various possible arguments. For example:
Constructs a wrapper for a program with various possible arguments. It is defined as part of 2 setup-hooks named `makeWrapper` and `makeBinaryWrapper` that implement the same bash functions. Hence, to use it you have to add `makeWrapper` to your `nativeBuildInputs`. Here's an example usage:

```bash
# adds `FOOBAR=baz` to `$out/bin/foo`’s environment
Expand All @@ -786,9 +786,11 @@ makeWrapper $out/bin/foo $wrapperfile --set FOOBAR baz
makeWrapper $out/bin/foo $wrapperfile --prefix PATH : ${lib.makeBinPath [ hello git ]}
```

There’s many more kinds of arguments, they are documented in `nixpkgs/pkgs/build-support/setup-hooks/make-wrapper.sh`.
There’s many more kinds of arguments, they are documented in `nixpkgs/pkgs/build-support/setup-hooks/make-wrapper.sh` for the `makeWrapper` implementation and in `nixpkgs/pkgs/build-support/setup-hooks/make-binary-wrapper.sh` for the `makeBinaryWrapper` implementation.

`wrapProgram` is a convenience function you probably want to use most of the time.
`wrapProgram` is a convenience function you probably want to use most of the time, implemented by both `makeWrapper` and `makeBinaryWrapper`.

Using the `makeBinaryWrapper` implementation is usually preferred, as it creates a tiny _compiled_ wrapper executable, that can be used as a shebang interpreter. This is needed mostly on Darwin, where shebangs cannot point to scripts, [due to a limitation with the `execve`-syscall](https://stackoverflow.com/questions/67100831/macos-shebang-with-absolute-path-not-working). Compiled wrappers generated by `makeBinaryWrapper` can be inspected with `less <path-to-wrapper>` - by scrolling past the binary data you should be able to see the shell command that generated the executable and there see the environment variables that were injected into the wrapper.

### `substitute` \<infile\> \<outfile\> \<subs\> {#fun-substitute}

Expand Down Expand Up @@ -863,9 +865,9 @@ someVar=$(stripHash $name)

### `wrapProgram` \<executable\> \<makeWrapperArgs\> {#fun-wrapProgram}

Convenience function for `makeWrapper` that automatically creates a sane wrapper file. It takes all the same arguments as `makeWrapper`, except for `--argv0`.
Convenience function for `makeWrapper` that replaces `<\executable\>` with a wrapper that executes the original program. It takes all the same arguments as `makeWrapper`, except for `--inherit-argv0` (used by the `makeBinaryWrapper` implementation and `--argv0` (used by both `makeWrapper` and `makeBinaryWrapper` wrapper implementations).
doronbehar marked this conversation as resolved.
Show resolved Hide resolved

It cannot be applied multiple times, since it will overwrite the wrapper file.
If you will apply it multiple times, it will overwrite the wrapper file and you will end up with double wrapping, which should be avoided.

## Package setup hooks {#ssec-setup-hooks}

Expand Down
6 changes: 6 additions & 0 deletions maintainers/maintainer-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,12 @@
githubId = 251106;
name = "Daniel Bergey";
};
bergkvist = {
email = "tobias@bergkv.ist";
github = "bergkvist";
githubId = 410028;
name = "Tobias Bergkvist";
};
betaboon = {
email = "betaboon@0x80.ninja";
github = "betaboon";
Expand Down
Loading