Skip to content

Commit

Permalink
Update JS -> native dependencies to include transitive dependencies
Browse files Browse the repository at this point in the history
Followup to #18849
  • Loading branch information
sbc100 committed Feb 27, 2023
1 parent ca5f2bc commit b64ce68
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
23 changes: 21 additions & 2 deletions src/jsifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ function isDefined(symName) {
return false;
}

function getTransitiveDeps(symbol) {
const transitiveDeps = new Set();
const seen = new Set();
const toVisit = [symbol];
while (toVisit.length) {
const sym = toVisit.pop();
if (!seen.has(sym)) {
let directDeps = LibraryManager.library[sym + '__deps'] || [];
directDeps = directDeps.filter((d) => typeof d === 'string');
if (directDeps.length) {
directDeps.forEach(transitiveDeps.add, transitiveDeps);
toVisit.push(...directDeps);
}
seen.add(sym);
}
}
return Array.from(transitiveDeps);
}

function runJSify(symbolsOnly = false) {
const libraryItems = [];
const symbolDeps = {};
Expand Down Expand Up @@ -254,8 +273,8 @@ function ${name}(${args}) {

if (symbolsOnly) {
if (!isJsOnlySymbol(symbol) && LibraryManager.library.hasOwnProperty(symbol)) {
externalDeps = deps.filter((d) => !isJsOnlySymbol(d) && !(d in LibraryManager.library) && typeof d === 'string');
symbolDeps[symbol] = externalDeps;
var transtiveDeps = getTransitiveDeps(symbol);
symbolDeps[symbol] = transtiveDeps.filter((d) => !isJsOnlySymbol(d) && !(d in LibraryManager.library));
}
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/library_html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2359,7 +2359,7 @@ var LibraryHTML5 = {

emscripten_set_batterychargingchange_callback_on_thread__proxy: 'sync',
emscripten_set_batterychargingchange_callback_on_thread__sig: 'iii',
emscripten_set_batterychargingchange_callback_on_thread__deps: ['$registerBatteryEventCallback', '$battery', 'malloc'],
emscripten_set_batterychargingchange_callback_on_thread__deps: ['$registerBatteryEventCallback', '$battery'],
emscripten_set_batterychargingchange_callback_on_thread: function(userData, callbackfunc, targetThread) {
if (!battery()) return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
registerBatteryEventCallback(battery(), userData, true, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_BATTERYCHARGINGCHANGE') }}}, "chargingchange", targetThread);
Expand All @@ -2368,7 +2368,7 @@ var LibraryHTML5 = {

emscripten_set_batterylevelchange_callback_on_thread__proxy: 'sync',
emscripten_set_batterylevelchange_callback_on_thread__sig: 'iii',
emscripten_set_batterylevelchange_callback_on_thread__deps: ['$registerBatteryEventCallback', '$battery', 'malloc'],
emscripten_set_batterylevelchange_callback_on_thread__deps: ['$registerBatteryEventCallback', '$battery'],
emscripten_set_batterylevelchange_callback_on_thread: function(userData, callbackfunc, targetThread) {
if (!battery()) return {{{ cDefine('EMSCRIPTEN_RESULT_NOT_SUPPORTED') }}};
registerBatteryEventCallback(battery(), userData, true, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_BATTERYLEVELCHANGE') }}}, "levelchange", targetThread);
Expand Down

0 comments on commit b64ce68

Please sign in to comment.