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

LibNode Discovery #425

Merged
merged 18 commits into from
Feb 18, 2025
Merged

LibNode Discovery #425

merged 18 commits into from
Feb 18, 2025

Conversation

wasabii
Copy link
Contributor

@wasabii wasabii commented Feb 11, 2025

Resubmitting a PR I did directly against @vmoroz's local fork earlier. As we talked about over there, right now, this PR has the LibNode packages pointing to my local fork, where the runtimes/{rid}/native directory is populated correctly. The PR thus is not ready to be accepted until the upstream LibNode packages are fixed up. But getting the discovery code visible I thought would be beneficial.

Allow null to be passed as libpath. The result is that a series of procedures for locating the libnode library is done.

a) On Core+ platforms, NativeLibrary is used directly with a relative path off of the assembly. This causes a search across the applications .deps.json. This is the ideal scenario as long as the LibNode packages deliver the library into runtimes/{rid}/native.
b) On Framework platforms a search procedure is used. First, libnode is attempted to be loaded by relative name directly. This handles the situation where the library is directly available in some way. Such as relative to the executable. Second runtimes/{rid}/native is examined with a known RID based on current platform.

A few local NativeLibrary methods were improved.

  • Load was updated to support non-Windows platforms. This handles the scenario of Framework on ~Windows. Such as Mono.
  • TryLoad was introduced to probe paths during discovery.
  • GetExport/TryGetExport was updated to support non-Windows platforms. This handles the scenario of Framework on ~Windows. Such as Mono.
  • dlerror() was introduced to handle the situation of null exports. Which should not reaaaaly happen in libnode. But is technically correct.
  • The pinvokes to libdl are technically out of date. dl was merged into libc on Linux. And was already present in libc on OS X. But these are left.
  • Expects to use Microsoft.JavaScript.LibNode version that deposit native libraries properly.
    Change tests to not need a hard coded libnode path.

…ocedures for locating the libnode library is done.

a) On Core+ platforms, NativeLibrary is used directly with a relative path off of the assembly. This causes a search across the applications .deps.json. This is the ideal scenario as long as the LibNode packages deliver the library into runtimes/{rid}/native.
b) On Framework platforms a search procedure is used. First, libnode is attempted to be loaded by relative name directly. This handles the situation where the library is directly available in some way. Such as relative to the executable. Second runtimes/{rid}/native is examined with a known RID based on current platform.

A few local NativeLibrary methods were improved.

Load was updated to support non-Windows platforms. This handles the scenario of Framework on ~Windows. Such as Mono.
TryLoad was introduced to probe paths during discovery.
GetExport/TryGetExport was updated to support non-Windows platforms. This handles the scenario of Framework on ~Windows. Such as Mono.
dlerror() was introduced to handle the situation of null exports. Which should not reaaaaly happen in libnode. But is technically correct.
The pinvokes to libdl are technically out of date. dl was merged into libc on Linux. And was already present in libc on OS X. But these are left.
I made changes to NuGet.config, removing the react stuff and the disabled sources. I don't know what the goal was here, but this was required to get the code building for me.
Expects to use Microsoft.JavaScript.LibNode version that deposit native libraries properly.
Change tests to not need a hard coded libnode path.
Remove LibNodePath parameter and replace with property on settings.
Fix dlerror check. Should be zero.
…sed by the runtime's version of NativeLibrary.
…is that anything that has dl.so.2 as the proper library should have moved it to libc anyways. So I'm not sure what OS this actually applies to, but maybe there is something.
…al CLR version at which NativeLibrary appeared (future proofs change in compatibility).
@wasabii wasabii marked this pull request as ready for review February 16, 2025 02:25
@vmoroz
Copy link
Member

vmoroz commented Feb 16, 2025

@wasabii , the code formatter fails the PR validation. You can run the following script to fix some of the issues automatically.

dotnet format --no-restore --severity info --verbosity detailed 

@wasabii
Copy link
Contributor Author

wasabii commented Feb 16, 2025

@wasabii , the code formatter fails the PR validation. You can run the following script to fix some of the issues automatically.

dotnet format --no-restore --severity info --verbosity detailed 

That command just runs a bit then throws an exception. Unhandled exception: System.Exception: source text did not have an identifiable encoding

Anyway to identify the failures from the verification stuff above? Don't really see any....

@vmoroz
Copy link
Member

vmoroz commented Feb 16, 2025

@wasabii , the code formatter fails the PR validation. You can run the following script to fix some of the issues automatically.

dotnet format --no-restore --severity info --verbosity detailed 

That command just runs a bit then throws an exception. Unhandled exception: System.Exception: source text did not have an identifiable encoding

Anyway to identify the failures from the verification stuff above? Don't really see any....

I wonder if it is related to Windows platform somehow. Last time I did not see any issues.
If you do not mind, then I can fix it and update your PR.

Edit:
Never mind. I do not see any formatting issues on my side. I guess it is something else. Let me play with it.
I will start with updating the upstream packages that fail CodeQL.

@wasabii
Copy link
Contributor Author

wasabii commented Feb 16, 2025

I just read your edit. Hehe. Gotcha.

@vmoroz
Copy link
Member

vmoroz commented Feb 16, 2025

I just read your edit. Hehe. Gotcha.

I see the same behavior on Windows. Anyway, the CodeQL is passing. I will play with other issues.
The CodeQL issue was related to the appearance of the new version of .Net 9.0.2 and .Net 8.0.13.
My next step is to install them locally and see if the formatter will make any difference.

@vmoroz
Copy link
Member

vmoroz commented Feb 16, 2025

The 9.0.2 throws the same exception as you reported above.
This issue is reported here dotnet/sdk#46780 against dotnet 9.0.2.
No solution yet.

@vmoroz
Copy link
Member

vmoroz commented Feb 16, 2025

This commit has all the required formatting issues: vmoroz@8587002
I cannot update this PR because this options is now off by default unless a developer enables it explicitly.

To fix the issue I had to switch the encoding of the files to CRLF for the formatter to run.
It seems that 9.0.2 developers never tested it for LF line ending files.

@wasabii
Copy link
Contributor Author

wasabii commented Feb 17, 2025

I pulled that commit in.

@vmoroz vmoroz merged commit e99e1d6 into microsoft:main Feb 18, 2025
24 checks passed
@vmoroz
Copy link
Member

vmoroz commented Feb 21, 2025

@wasabii , @jasongin , it seems I screwed up the NuGet release.
The right version that contains this PR is 0.9.5.
Though previously the build pipeline published version 0.9.6 which pretty much the same as the 0.9.4 due to my mistake.
I have unlisted the 0.9.6 from Nuget.org, but it may still cause issues in the short run.

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.

2 participants