-
Notifications
You must be signed in to change notification settings - Fork 312
Description
Assuming the target machine is the same architecture as the current machine (for this reason the suggestion would be to implement this behind a --binaries flag or similar), here's a suggested approach for remapping and emitting binaries.
The assumption is that the "patterns" for binary emission are generally only of a few types, and that we can build static analysis to detect those patterns and provide an adequate substitution for them through (1) detecting where the binary is based on this static analysis and (2) rewriting the locator code as we do for other fs relocations to point to this new binary location.
Detection Cases (not comprehensive, just what I can find on a quick review):
- Statically detect any calls to
node-pre-gyp's find method. (literally detectingrequire('node-pre-gyp').findand all its natural simple variations. Eg like in https://unpkg.com/grpc@1.16.1/src/grpc_extension.js. - Statically detect any calls to
require('bindings')('binding.node')and its associated lookup algorithm. - Direct requires to
.nodebinaries being treated as emitted relocated externals
Rewriting
The rewriting just full replaces the statically known path. Eg require('node-pre-gyp').find(staticExpression) -> __dirname + '/emitted.node'. This is exactly like the asset relocator already does, but simply extended to these more complex patterns.
There may still be edge cases that are not analyzable, but this partial executor already takes into account all path functions, __dirname and __filename expressions. We can tailor the analysis to the real-world test cases, and likely get quite far here too.