Skip to content

[RemoveImports] Support specifying imports to remove with arguments - #9395

Open
jeremy-code wants to merge 3 commits into
WebAssembly:mainfrom
jeremy-code:dev/remove-imports-arguments
Open

jeremy-code wants to merge 3 commits into
WebAssembly:mainfrom
jeremy-code:dev/remove-imports-arguments

Conversation

@jeremy-code

Copy link
Copy Markdown
Contributor

If passed with no arguments, the current behavior where all imports are removed is preserved. If passed with a comma-separated list of imports (with format module.base or wildcards) or a response file, only the specified imports will be removed.

This might be useful if, for example, you are compiling a WebAssembly module with WASI, but do not want certain functions (e.g. filesystem, pthreads) to be implemented. There may also be niche usage with wasm-merge (e.g. merging with an upstream WebAssembly binary where you don't want to provide all imports).

@tlively
tlively self-requested a review November 14, 2026 10:33
toRemove.insert(func->name);
return;
}
auto full = func->module.toString() + '.' + func->base.toString();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same syntax as the Asyncify pass:

static std::string getFullImportName(Name module, Name base) {
return module.toString() + '.' + base.toString();
}
. There might be weird behavior since both module and function names can be any valid UTF-8 strings. At the very least, WebAssembly ESM integration imports should be fine (the only periods that such exist are at the beginning for relative files and the file extension).

@jeremy-code
jeremy-code force-pushed the dev/remove-imports-arguments branch from 30705c3 to 9902962 Compare November 14, 2026 10:40
@jeremy-code jeremy-code changed the title [Remove imports] Support specifying imports to remove with arguments [RemoveImports] Support specifying imports to remove with arguments Nov 14, 2026
Comment thread src/passes/RemoveImports.cpp Resolved

@kripken kripken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm % minor suggestion

@kripken kripken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually, one last thing, is there a test for removing all imports? I don't see an old one, so please add one to make sure nothing regressed here.

If passed with no arguments, the current behavior where all imports are removed is preserved. If passed with a comma-separated list of imports (with format module.base or wildcards) or a response file, only the specified imports will be removed.
@jeremy-code
jeremy-code force-pushed the dev/remove-imports-arguments branch from f502b6f to e14dac8 Compare November 26, 2026 06:05
@jeremy-code

Copy link
Copy Markdown
Contributor Author

Got it, that's been done.

This branch has not been deployed

No deployments
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