thi-ng / umbrella

⛱ Broadly scoped ecosystem & mono-repository of 199 TypeScript projects (and ~180 examples) for general purpose, functional, data driven development
https://thi.ng
Apache License 2.0
3.38k stars 150 forks source link

[simd] Instructions on building locally? #417

Closed zachrattner closed 12 months ago

zachrattner commented 1 year ago

I like the provided SIMD functions but want to add a few of my own to go alongside this. To do this, I wanted to clone the repo, build it locally, and test out modifications.

Cloning the repo and building worked great, but using the locally compiled version does not. If someone could help me get this set up, I'd be happy to update the README.md file with the new steps.

  1. Clone repo works great: git clone https://github.com/thi-ng/umbrella.git
  2. Building works: cd umbrella && yarn install && yarn build
  3. Using it does not. In package.json:
    "dependencies": {
      "my-umbrella": "file:./umbrella"
    },
    "scripts": {
        "compare": "node compare.js"
    },

Then when I'm trying to modify this demo code:

import { init } from "@thi.ng/simd";

// the WASM module doesn't specify any own memory and it must be provided by user
// the returned object contains all available vector functions & memory views
// (an error will be thrown if WASM isn't available or SIMD unsupported)
const simd = init(new WebAssembly.Memory({ initial: 1 }));

To use my local package instead of the published one:

import { init } from "my-umbrella";

// the WASM module doesn't specify any own memory and it must be provided by user
// the returned object contains all available vector functions & memory views
// (an error will be thrown if WASM isn't available or SIMD unsupported)
const simd = init(new WebAssembly.Memory({ initial: 1 }));

I run with this command:

yarn compare

And I get this error:

node:internal/modules/esm/resolve:188
  const resolvedOption = FSLegacyMainResolve(packageJsonUrlString, packageConfig.main, baseStringified);
                         ^

Error: Cannot find package '/Users/zach/code/myProject/test/node_modules/my-umbrella/package.json' imported from /Users/zach/code/myProject/test/compare.js
    at legacyMainResolve (node:internal/modules/esm/resolve:188:26)
    at packageResolve (node:internal/modules/esm/resolve:767:14)
    at moduleResolve (node:internal/modules/esm/resolve:829:20)
    at defaultResolve (node:internal/modules/esm/resolve:1034:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:375:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:344:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:220:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36) {
  code: 'ERR_MODULE_NOT_FOUND'

However, I can confirm this file does indeed exist:

/Users/zach/code/myProject/test/node_modules/my-umbrella/package.json

Any ideas?

postspectacular commented 1 year ago

Hi @zachrattner - I'm not sure what you're trying to do here re: defining this "my-umbrella" package. Also from the above it isn't quite clear which package.json file you've edited (the main package of the entire umbrella monorepo or just the package of the SIMD library)...

If you're trying to add more SIMD functions you'll have to add them in two places:

Then rebuild both the WASM binary and wrapper via: (cd packages/simd && yarn build:binary && yarn build)

Hope that helps!

zachrattner commented 12 months ago

I ended up implementing in assembly script vs trying to hack this up. Thanks for the help!