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

No in-build execution for CMake managed builds #22060

Closed
ck3d opened this issue Jan 23, 2017 · 14 comments · Fixed by #108496
Closed

No in-build execution for CMake managed builds #22060

ck3d opened this issue Jan 23, 2017 · 14 comments · Fixed by #108496
Assignees
Labels
0.kind: bug Something is broken 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: developer experience 9.needs: clean-up

Comments

@ck3d
Copy link
Contributor

ck3d commented Jan 23, 2017

Issue description

I try to migrate a library written in C++ build via CMake to Nix. The test executables also written in C++ are part of this project. CMake allows in-build execution (and therefor in-build testing), because it sets the RPATH for the build executable.

Nixpkgs skips adding this RPATH by setting CMAKE_SKIP_BUILD_RPATH`. This behavior breaks the possibility to test the library or call built executables during build.

Workarounds

  • Expand LD_LIBRARY_PATH; Following command gives an overview how many derivations tackle this issue.
    .../nixpkgs $ git grep -E "LD_LIBRARY_PATH.*pwd"
  • Install before checking/install project before checking/testing

Proposal

The canonical behavior of CMake should be preserved and CMAKE_SKIP_BUILD_RPATH should not be set.

What do you think about this issue?

@cpages
Copy link
Contributor

cpages commented Feb 5, 2017

That behavior is a bit annoying, but there is a reason CMAKE_SKIP_BUILD_RPATH is set, as is explained on the comment above the line you referred. Specifically, cmake clears the rpath after the build if the SKIP option is not set, breaking all the dependencies that are set by nix.

So it's not as easy as just not setting that flag. Did you have a specific solution in mind?

@ck3d
Copy link
Contributor Author

ck3d commented Feb 9, 2017

Only if CMake would use RPATH for local and RUNPATH for global dependencies. But CMake uses put all the dependencies into RUNPATH.

No I have no solution.
I think we should document the limitation.

@globin
Copy link
Member

globin commented Feb 15, 2017

cc @viric

@mmahut
Copy link
Member

mmahut commented Aug 11, 2019

Are there any updates to this issue, please?

@jmillerpdt jmillerpdt mentioned this issue Sep 25, 2019
10 tasks
@bjornfor
Copy link
Contributor

I dug in the nixpkgs tree and found that some packages actually set -DCMAKE_SKIP_BUILD_RPATH=OFF, to reverse the effect of the setup hook and be able to run binaries from the build tree.

Digging a bit more I found that -DCMAKE_SKIP_BUILD_RPATH=ON was added in 2009. Commit f3c2348 added it to the cmake setup hook after it having been manually set in a few packages earlier that year.

In 2016 an attempt was made to change from -DCMAKE_SKIP_BUILD_RPATH=ON to -DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE, but it was reverted due to a blocking darwin issue: d5d4606. I'm not sure that commit would have fixed this issue, but the discussion that lead up the the revert is worth a read:#15881.

After that revert, -DCMAKE_SKIP_BUILD_RPATH=OFF popped up in various package to workaround this issue.

I wonder if we could try removing it again, possibly only for Linux?

@knedlsepp
Copy link
Member

I dug in the nixpkgs tree and found that some packages actually set -DCMAKE_SKIP_BUILD_RPATH=OFF, to reverse the effect of the setup hook and be able to run binaries from the build tree.

Digging a bit more I found that -DCMAKE_SKIP_BUILD_RPATH=ON was added in 2009. Commit f3c2348 added it to the cmake setup hook after it having been manually set in a few packages earlier that year.

In 2016 an attempt was made to change from -DCMAKE_SKIP_BUILD_RPATH=ON to -DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE, but it was reverted due to a blocking darwin issue: d5d4606. I'm not sure that commit would have fixed this issue, but the discussion that lead up the the revert is worth a read:#15881.

After that revert, -DCMAKE_SKIP_BUILD_RPATH=OFF popped up in various package to workaround this issue.

I wonder if we could try removing it again, possibly only for Linux?

I'd highly appreciate that. I've had the same issue too. 😀

@stale
Copy link

stale bot commented Aug 22, 2020

Hello, I'm a bot and I thank you in the name of the community for opening this issue.

To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.

If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.

Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 22, 2020
@knedlsepp
Copy link
Member

Still important to me.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 31, 2020
@knedlsepp
Copy link
Member

knedlsepp commented Jan 5, 2021

@LnL7 As this bit me again today while developing on a project, I'm wondering if you could help with fixing this issue. The previous attempt to fix this failed because of some issues on darwin, so you seem like the perfect person to turn to (being both maintainer of cmake and a (the?) top darwin contributor).

@stale
Copy link

stale bot commented Jul 8, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 8, 2021
ttuegel pushed a commit that referenced this issue Jul 11, 2022
This should simplify using `nix-shell -A` or `nix develop` to develop
CMake based projects. CMake features a mechanism to use a different
RPATH for all executables in the build directory and only rewrite these
RPATHs on installation. This makes it possible to run executables
already from the build directory without having to set LD_LIBRARY_PATH.
This should simplify the checkPhase for cmake based projects and
hopefully not break anything.

Fixes: #22060
@Artturin
Copy link
Member

pr merged

@Artturin
Copy link
Member

Artturin commented Jul 15, 2022

can someone add a section to @jtojnar's https://github.com/jtojnar/cmake-snips on how to fix this without
"-DCMAKE_SKIP_BUILD_RPATH=ON" workaround

#181243
#181540

the errors are
# RPATH of binary /nix/store/.../bin/... contains a forbidden reference to /build/
# file RPATH_CHANGE could not write new RPATH

example of a error

https://hydra.nixos.org/build/183517097/log
https://github.com/SIPp/sipp/blob/f44d0cf5dec0013eff8fd7b4da885d455aa82e0e/CMakeLists.txt#L125

Install the project...
-- Install configuration: "Release"
-- Installing: /nix/store/wm6dndxvsnsxfv95dm3vgg7jm6b1vkzi-sipp-3.6.1/bin/sipp
CMake Error at cmake_install.cmake:55 (file):
  file RPATH_CHANGE could not write new RPATH:

    

  to the file:

    /nix/store/wm6dndxvsnsxfv95dm3vgg7jm6b1vkzi-sipp-3.6.1/bin/sipp

  The current RUNPATH is:

    /nix/store/wm6dndxvsnsxfv95dm3vgg7jm6b1vkzi-sipp-3.6.1/lib64:/nix/store/wm6dndxvsnsxfv95dm3vgg7jm6b1vkzi-sipp-3.6.1/lib:/nix/store/pkv4ngqc7arfqpr1bsn1bappvms9xbfg-ncurses-6.3-p20220507/lib:/nix/store/ff98lqrrlndgcai7hjrw50pjgdfmnixr-libpcap-1.10.1/lib:/nix/store/c8fc7saagp0vm5ll5mccpfnhg957pfya-openssl-1.1.1q/lib:/nix/store/x4h0a3mv3mw2sv3j2ysrl4wsacfrg7kq-lksctp-tools-1.0.17/lib:/nix/store/mhhlymrg2m70r8h94cwhv2d7a0c8l7g6-glibc-2.34-210/lib:/nix/store/xjmm9xg5sq47q63cbf447qalz9fmwp0v-gcc-11.3.0-lib/lib

  which does not contain:

    /var/empty/local/lib:

  as was expected.


make: *** [Makefile:100: install] Error 1

@lopsided98
Copy link
Contributor

lopsided98 commented Sep 20, 2022

What actually is the root cause of the # RPATH of binary ... contains a forbidden reference to /build/ error? I can't seem to find any examples where that has been fixed without setting -DCMAKE_SKIP_BUILD_RPATH=ON.

@bjornfor
Copy link
Contributor

bjornfor commented Oct 2, 2022

What actually is the root cause of the # RPATH of binary ... contains a forbidden reference to /build/ error? I can't seem to find any examples where that has been fixed without setting -DCMAKE_SKIP_BUILD_RPATH=ON.

AFAIK, it's due to bad cmake code in upstream projects. If the cmake code installs binaries with install(FILES ...) or install(DIRECTORY ...), instead of the proper install(TARGETS ...), then cmake will not fixup the rpath in the binaries inside the install tree. The nixpkgs setup-hook audit-tmpdir.sh then detects the bad rpath reference and emits RPATH of binary $i contains a forbidden reference to $TMPDIR/".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: developer experience 9.needs: clean-up
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants