-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Reimplement resolve_path
in JS NFC
#23935
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
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ef8c6e1
wip
ryanking13 49925d8
wip
ryanking13 ceef912
debug
ryanking13 b805542
Proxy _dylink_resolve_path_js to main thread
hoodmane e9853d2
Revert debug
ryanking13 bcd1484
cast bigint to see what happen
ryanking13 6d946c8
Use decrement rather than subtracting one to handle memory 64 case
hoodmane 4801daf
Simpler
hoodmane eb04eae
Fix
hoodmane 5237f7c
Add __sig
hoodmane 96e222d
Merge branch 'main' into dylink-js
ryanking13 9c563ca
Remove debug flags
ryanking13 a83bd05
Also test LD_LIBRARY_PATH with wasm64
hoodmane 301a1b3
Add shell environment to wasm64 ld_library_path
hoodmane 53100c9
Revert "Add shell environment to wasm64 ld_library_path"
hoodmane 59a2344
Revert "Also test LD_LIBRARY_PATH with wasm64"
hoodmane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -656,7 +656,7 @@ var LibraryDylink = { | |||||
} | ||||||
#if DYLINK_DEBUG | ||||||
dbg(`loadModule: memory[${memoryBase}:${memoryBase + metadata.memorySize}]` + | ||||||
` table[${tableBasex}:${tableBase + metadata.tableSize}]`); | ||||||
` table[${tableBase}:${tableBase + metadata.tableSize}]`); | ||||||
#endif | ||||||
|
||||||
// This is the export map that we ultimately return. We declare it here | ||||||
|
@@ -1172,6 +1172,96 @@ var LibraryDylink = { | |||||
#endif | ||||||
}, | ||||||
|
||||||
$locateLibraryFromFS__deps: ['$FS'], | ||||||
$locateLibraryFromFS: (filename, searchDirs, maxLength = Infinity) => { | ||||||
// Find the library in the filesystem. | ||||||
// returns null if not found. | ||||||
if (typeof FS.lookupPath !== 'function') { | ||||||
// wasmfs does not implement FS.lookupPath | ||||||
#if DYLINK_DEBUG | ||||||
dbg("locateLibraryFromFS: FS.lookupPath not implemented"); | ||||||
#endif | ||||||
return null; | ||||||
} | ||||||
|
||||||
var candidates = []; | ||||||
if (filename.charAt(0) === '/') { // abs path | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shorter:
Suggested change
|
||||||
candidates.push(filename); | ||||||
} else if (searchDirs) { | ||||||
for (var dir of searchDirs) { | ||||||
// PATH.join does not work well with symlinks | ||||||
candidates.push(dir + '/' + filename); | ||||||
} | ||||||
} else { | ||||||
return null; | ||||||
} | ||||||
|
||||||
#if DYLINK_DEBUG | ||||||
dbg("locateLibraryFromFS: candidates " + candidates); | ||||||
#endif | ||||||
|
||||||
for (var path of candidates) { | ||||||
try { | ||||||
var res = FS.lookupPath(path); | ||||||
if (res.node.isDir || res.node.isDevice) { | ||||||
continue | ||||||
} | ||||||
|
||||||
if (res.path.length >= maxLength) { | ||||||
continue | ||||||
} | ||||||
#if DYLINK_DEBUG | ||||||
dbg(`locateLibraryFromFS: found ${res.path} for (${filename})`); | ||||||
#endif | ||||||
return res.path; | ||||||
} catch(e) { | ||||||
#if DYLINK_DEBUG | ||||||
dbg(`locateLibraryFromFS: ${path} not found: ${e}`); | ||||||
#endif | ||||||
// do nothing is file is not found | ||||||
} | ||||||
} | ||||||
|
||||||
return null; | ||||||
}, | ||||||
|
||||||
$getDefaultLibDirs__deps: ['$ENV'], | ||||||
$getDefaultLibDirs__proxy: 'sync', | ||||||
$getDefaultLibDirs: () => { | ||||||
var ldLibraryPath = ENV['LD_LIBRARY_PATH'] | ||||||
#if DYLINK_DEBUG | ||||||
dbg(`getDefaultLibDirs: LD_LIBRARY_PATH=${ldLibraryPath}`); | ||||||
#endif | ||||||
return ldLibraryPath?.split(':') ?? []; | ||||||
}, | ||||||
|
||||||
_dylink_resolve_path_js__deps: ['$UTF8ToString', '$stringToUTF8', '$locateLibraryFromFS', '$getDefaultLibDirs'], | ||||||
_dylink_resolve_path_js__proxy: 'sync', | ||||||
_dylink_resolve_path_js: (cbuf, cfile, buflen) => { | ||||||
var cfilePtr = cfile; | ||||||
|
||||||
#if MEMORY64 | ||||||
cfilePtr = Number(cfilePtr); | ||||||
buflen = Number(buflen) | ||||||
#endif | ||||||
hoodmane marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
var file = UTF8ToString(cfilePtr); | ||||||
|
||||||
if (file.startsWith("/")) { | ||||||
return cfile; | ||||||
} | ||||||
|
||||||
var res = locateLibraryFromFS(file, getDefaultLibDirs(), buflen - 1); | ||||||
if (!res) { | ||||||
#if DYLINK_DEBUG | ||||||
dbg("_dylink_resolve_path_js: fail to locate " + file); | ||||||
#endif | ||||||
return cfile; | ||||||
} | ||||||
stringToUTF8(res, cbuf, buflen); | ||||||
return cbuf; | ||||||
}, | ||||||
|
||||||
// Async version of dlopen. | ||||||
_emscripten_dlopen_js__deps: ['$dlopenInternal', '$callUserCallback', '$dlSetError'], | ||||||
_emscripten_dlopen_js: (handle, onsuccess, onerror, user_data) => { | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly shorter: