Skip to content

build: look for libnode.so in lib subdirectory #58213

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

Merged
merged 1 commit into from
May 22, 2025

Conversation

khardix
Copy link
Contributor

@khardix khardix commented May 7, 2025

When building with --shared, ninja will output the libnode.so into a {build_dir}/lib directory, not in the root {build_dir}. This fixes the install script to look for it in the correct place.


Found during review of a Fedora rpm, where we apparently been moving the libnode.so manually to the root of the build directory manually this entire time. Let's see if we can stop doing that. 😅

@nodejs-github-bot nodejs-github-bot added build Issues and PRs related to build files or the CI. needs-ci PRs that need a full CI run. python PRs and issues that require attention from people who are familiar with Python. labels May 7, 2025
@khardix
Copy link
Contributor Author

khardix commented May 7, 2025

CC @richardlau FYI

@richardlau
Copy link
Member

@khardix Unfortunately the make and ninja generators in gyp use different output directories, and this breaks non-ninja builds.
e.g.

$ tools/install.py --dest-dir /tmp/testinstl --prefix "" install
installing /tmp/testinstl/bin/node
installing /tmp/testinstl/lib/libnode.so.137
Traceback (most recent call last):
  File "/home/rlau/sandbox/github/node/tools/install.py", line 426, in <module>
    run(parse_options(sys.argv[1:]))
  File "/home/rlau/sandbox/github/node/tools/install.py", line 379, in run
    files(options, install)
  File "/home/rlau/sandbox/github/node/tools/install.py", line 185, in files
    action(options, [os.path.join(options.build_dir, 'lib', output_lib)],
  File "/home/rlau/sandbox/github/node/tools/install.py", line 84, in install
    try_copy(options, path, dest)
  File "/home/rlau/sandbox/github/node/tools/install.py", line 73, in try_copy
    return shutil.copy2(source_path, target_path)
  File "/usr/lib64/python3.9/shutil.py", line 444, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/lib64/python3.9/shutil.py", line 264, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/home/rlau/sandbox/github/node/out/Release/lib/libnode.so.137'

Using make instead of ninja and configure --shared, I end up with:

$ find . -type f -name "libnode.so.*"
./out/Release/obj.target/libnode.so.137
./out/Release/.deps/home/rlau/sandbox/github/node/out/Release/obj.target/libnode.so.137.d
./out/Release/.deps/home/rlau/sandbox/github/node/out/Release/libnode.so.137.d
./out/Release/libnode.so.137
$

I'm not sure if there's an easy way for install.py to know whether ninja was used. If configure is passed --ninja then I believe the generated config.mk will contain

BUILD_WITH=ninja

(BUILD_WITH will not be present there at all if --ninja is NOT passed to configure).

@khardix
Copy link
Contributor Author

khardix commented May 7, 2025

Thanks for the analysis; I'll try to take another look at this next week (we have holidays in Czechia this one).

Copy link
Member

@richardlau richardlau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes as per #58213 (comment) (since this now has an approval).

@khardix
Copy link
Contributor Author

khardix commented May 20, 2025

I tried to look into various places whether the ninja and/or the make generator could be persuaded to output files to the same places as the other one, but did not find anything. Granted, I'm not versed in using these tools too much, so it's entirely possible I missed something obvious.

I whipped the new commit as an alternative – the tools/install.py will now try to look at both possible places and install the first libnode.so that actually exist. It's a bit of a brute force approach with it's own drawbacks, but it should (mostly) work for both generators and not require significant changes anywhere else. 🤷 Let me know what you think about it.

@khardix khardix marked this pull request as draft May 20, 2025 12:10
As the actual location of built libnode.so may differ depending on which
system was used to orchestrate the build (ninja or make),
multiple places should be searched for it's location.
@khardix khardix marked this pull request as ready for review May 20, 2025 14:27
@richardlau richardlau added the request-ci Add this label to start a Jenkins CI on a PR. label May 21, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 21, 2025
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@richardlau richardlau added the commit-queue Add this label to land a pull request using GitHub Actions. label May 22, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label May 22, 2025
@nodejs-github-bot nodejs-github-bot merged commit cb88e99 into nodejs:main May 22, 2025
72 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in cb88e99

@richardlau richardlau added lts-watch-v20.x PRs that may need to be released in v20.x lts-watch-v22.x PRs that may need to be released in v22.x labels May 22, 2025
targos pushed a commit that referenced this pull request May 31, 2025
As the actual location of built libnode.so may differ depending on which
system was used to orchestrate the build (ninja or make),
multiple places should be searched for it's location.

PR-URL: #58213
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
aduh95 pushed a commit that referenced this pull request Jun 10, 2025
As the actual location of built libnode.so may differ depending on which
system was used to orchestrate the build (ninja or make),
multiple places should be searched for it's location.

PR-URL: #58213
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
@aduh95 aduh95 added backported-to-v22.x PRs backported to the v22.x-staging branch. and removed lts-watch-v22.x PRs that may need to be released in v22.x labels Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported-to-v22.x PRs backported to the v22.x-staging branch. build Issues and PRs related to build files or the CI. lts-watch-v20.x PRs that may need to be released in v20.x needs-ci PRs that need a full CI run. python PRs and issues that require attention from people who are familiar with Python.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants