Giter Site home page Giter Site logo

devappd / emscripten-sdk-npm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bvibber/emsdk-npm

3.0 0.0 3.0 182 KB

Install the Emscripten SDK using NPM. Provides a CLI and API for Node.js.

Home Page: https://www.npmjs.com/package/emscripten-sdk

License: MIT License

JavaScript 99.69% C++ 0.31%
emscripten emscripten-sdk emsdk webassembly wasm npm nodejs

emscripten-sdk-npm's Introduction

emscripten-sdk

test-branch emscripten-sdk mit-license

An NPM wrapper for the Emscripten SDK.

This package installs the Emscripten compiler and provides a command line and a JS interface to use in your build scripts.

You may install one of these two packages:

  • emscripten-sdk -- Control the SDK version via the NPM package version. Recommended.
  • emscripten-sdk-npm -- Control the SDK version via CLI/API parameters. For advanced use.

Command line usage

npx emsdk-checkout
# To update SDK tags, run both `npx emsdk-pull` and `npx emsdk update-tags`
npx emsdk install <version>
npx emsdk activate <version>
npx emsdk-run emcc test/test.c -o test/test.html

The version parameter is not required when using the emscripten-sdk package.

JavaScript usage

const emsdk = require('emsdk-npm');

emsdk.checkout()
.then(() => emsdk.update())
.then(() => emsdk.install(version))
.then(() => emsdk.activate(version))
.then(() => emsdk.run(
    'emcc',
    [
        // Arguments
        'test/test.c', '-o', 'test/test.html'
    ], 
    { 
        // child_process.spawn options, e.g., cwd
    }
))
.catch((err) => {
    // handle err...
});

The JS interface will skip installing the SDK and version if they already exist.

The version parameter is not required when using the emscripten-sdk package.

Install

npm install --save-dev emscripten-sdk

Before you install this package, you must install Python 3.6+ on your system. You may download it at python.org or your OS's package manager.

By default, the SDK is installed into your node_modules tree. You may specify a custom path by modifying your NPM config via one of the commands below. Do this before you install the package:

Action Command
Save the path to your project .npmrc npm config --userconfig "/your/project/root/.npmrc" set emsdk "/your/absolute/custom/path"
Save the path to your user .npmrc npm config set emsdk "/your/absolute/custom/path"
Set an environment variable set NPM_CONFIG_EMSDK=/your/absolute/custom/path
Use a config argument to NPM temporarily npm [command] --emsdk="/your/absolute/custom/path"

Version selection

If you install the emscripten-sdk package, then the Emscripten version is selected via the NPM package version. Change the version you need by editing your package.json.

For example, to force version 1.40.1, you specify the NPM tag as sdk-1.40.1. On the command line:

npm install --save-dev [email protected]

You may only specify single versions this way. You may not specify version ranges. If you do not specify a version, then the latest version will be selected.

If you install the emscripten-sdk-npm package, then you will specify the version parameter in the command line and JS API. To force version 1.40.1, you specify 1.40.1. To select the most recent version, you specify latest.

Upgrading the SDK

If you install the emscripten-sdk package, then you are locked into your selected SDK version unless you opt-in to a newer version. If you selected latest, then you are locked into the most recent version at the time of installation.

To upgrade, enter this command once a new version is published:

npm install --save-dev emscripten-sdk@latest

If you install the emscripten-sdk-npm package, then you will receive updates so long as you update the SDK store via npx emsdk-pull or the API emscripten.update(), then install the latest SDK version.

License

MIT License.

emscripten-sdk-npm's People

Contributors

bvibber avatar devappd avatar sxxov avatar

Stargazers

 avatar  avatar  avatar

emscripten-sdk-npm's Issues

Error retrieving installed EMSDK version: ENOENT: no such file or directory, open '<sdk-location>\emscripten-releases-tags.txt'

Problem

This PR in the emsdk repo replaced emscripten-releases-tags.txt with emscripten-releases-tags.json. Parsing this file works exactly like the .txt version. This makes the getReleasesTags function in common.js fail.

I noticed this issue when I attempted to make use of emscripten-build in a project. I believe the issue also arises when attempting to install emscripten-sdk

Steps to Reproduce

Attempt to use npx emscripten build in a project with emscripten-build as a dependency.

Suggested Solution

Replace .txt in the file linked above with .json

Make emsdk-npm package versions follow EMSDK releases

To follow this versioning scheme, make the NPM releases consistent with EMSDK. (This concerns emsdk-npm only).

  • Implement this by git branching for each EMSDK version. Branches are named v2.0.11, v2.0.10, etc. In each branch, store a default_version.js file that contains the EMSDK version string. This file sets the release to download for the rest of the package. Don't make the version string modifiable by the user. package.json is also edited to reflect the version.
  • Install EMSDK on npm install step when version is hardcoded
  • Make a CI runner to:
    • Mergemain changes to each version branch
    • Publish updated version branches
  • Make a CI runner to:
  • Investigate whether NPM recognizes +build version syntax and ranges them correctly. The +build part will track each main code merge. (e.g. v2.0.11+1609425262 represents the main revision dated 12/31/2020 that serves EMSDK 2.0.11)
  • Track separate NPM packages for the following scenarios:
    • emscripten-sdk: Versioned packages in llvm backend, e.g., [email protected], [email protected], etc.
    • emscripten-sdk-npm: Generic package for full control: e.g., requesting latest, fastcomp, tot

Versioning syntax

Bring up-to-date with latest emsdk changes

Workaround for users: Depend on the force-2.0.14 branch until changes can be made. This means that 2.0.14 is the latest fully working release.

In package.json:

"emscripten-sdk-npm": "devappd/emscripten-sdk-npm#force-2.0.14",

The package version in this branch is 0.3.3-1, which is a minor + prerelease digit up from NPM.

Test failure log:

  emsdk-npm JavaScript API
    checkout()
Cloning into 'D:\projects\emscripten\emscripten-build\emsdk-npm\test\emsdk-test'...
remote: Enumerating objects: 2829, done.
remote: Counting objects: 100% (91/91), done.
remote: Compressing objects: 100% (49/49), done.
Receiving objects: 100% (2829/2829), 1.49 MiB | 1.47 MiB/s, done. 2738
Resolving deltas:  13% (217/1806)
Resolving deltas: 100% (1806/1806), done.
      √ should write emsdk.py to the install dir (3340ms)
    update()
Already up to date.
`update-tags` is not longer needed.  To install the latest tot release just run `install tot`
      1) should write emscripten-releases-tot.txt to the install dir
    install()
Error retrieving installed EMSDK version: ENOENT: no such file or directory, open 'D:\projects\emscripten\emscripten-build\emsdk-npm\test\emsdk-test\upstream\.emsdk_version'
Resolving SDK alias 'latest' to '2.0.27'
Resolving SDK version '2.0.27' to 'sdk-releases-upstream-1ac46e3b84955231ab4a4f4cbe0c7ac28c86b8cc-64bit'
Installing SDK 'sdk-releases-upstream-1ac46e3b84955231ab4a4f4cbe0c7ac28c86b8cc-64bit'..
Installing tool 'node-14.15.5-64bit'..
Downloading: D:/Projects/emscripten/emscripten-build/emsdk-npm/test/emsdk-test/zips/node-v14.15.5-win-x64.zip from https://storage.googleapis.com/webassembly/emscripten-releases-builds/deps/node-v14.15.5-win-x64.zip, 30284821 Bytes
Unpacking 'D:/Projects/emscripten/emscripten-build/emsdk-npm/test/emsdk-test/zips/node-v14.15.5-win-x64.zip' to 'D:/Projects/emscripten/emscripten-build/emsdk-npm/test/emsdk-test/node/14.15.5_64bit'
Done installing tool 'node-14.15.5-64bit'.
Installing tool 'python-3.9.2-1-64bit'..
Downloading: D:/Projects/emscripten/emscripten-build/emsdk-npm/test/emsdk-test/zips/python-3.9.2-1-embed-amd64+pywin32.zip from https://storage.googleapis.com/webassembly/emscripten-releases-builds/deps/python-3.9.2-1-embed-amd64+pywin32.zip, 16982397 Bytes
Unpacking 'D:/Projects/emscripten/emscripten-build/emsdk-npm/test/emsdk-test/zips/python-3.9.2-1-embed-amd64+pywin32.zip' to 'D:/Projects/emscripten/emscripten-build/emsdk-npm/test/emsdk-test/python/3.9.2-1_64bit'
Done installing tool 'python-3.9.2-1-64bit'.
Installing tool 'java-8.152-64bit'..
Downloading: D:/Projects/emscripten/emscripten-build/emsdk-npm/test/emsdk-test/zips/portable_jre_8_update_152_64bit.zip from https://storage.googleapis.com/webassembly/emscripten-releases-builds/deps/portable_jre_8_update_152_64bit.zip, 69241499 Bytes
Unpacking 'D:/Projects/emscripten/emscripten-build/emsdk-npm/test/emsdk-test/zips/portable_jre_8_update_152_64bit.zip' to 'D:/Projects/emscripten/emscripten-build/emsdk-npm/test/emsdk-test/java/8.152_64bit'
Done installing tool 'java-8.152-64bit'.
Installing tool 'releases-upstream-1ac46e3b84955231ab4a4f4cbe0c7ac28c86b8cc-64bit'..
Downloading: D:/Projects/emscripten/emscripten-build/emsdk-npm/test/emsdk-test/zips/1ac46e3b84955231ab4a4f4cbe0c7ac28c86b8cc-wasm-binaries.zip from https://storage.googleapis.com/webassembly/emscripten-releases-builds/win/1ac46e3b84955231ab4a4f4cbe0c7ac28c86b8cc/wasm-binaries.zip, 423135197 Bytes   
Unpacking 'D:/Projects/emscripten/emscripten-build/emsdk-npm/test/emsdk-test/zips/1ac46e3b84955231ab4a4f4cbe0c7ac28c86b8cc-wasm-binaries.zip' to 'D:/Projects/emscripten/emscripten-build/emsdk-npm/test/emsdk-test/upstream'
Done installing tool 'releases-upstream-1ac46e3b84955231ab4a4f4cbe0c7ac28c86b8cc-64bit'.
Done installing SDK 'sdk-releases-upstream-1ac46e3b84955231ab4a4f4cbe0c7ac28c86b8cc-64bit'.
      2) should write the correct version to upstream/.emsdk_version
    activate()
      3) should write .emscripten to the install dir
    run()
Adding directories to PATH:
PATH += D:\Projects\emscripten\emscripten-build\emsdk-npm\test\emsdk-test

Setting environment variables:
PATH = D:\Projects\emscripten\emscripten-build\emsdk-npm\test\emsdk-test;D:\System\Programs\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\projects\emscripten\emscripten-build\emsdk-npm\node_modules\.bin;D:\Programs\Python\Python39\Scripts\;D:\Programs\Python\Python39\;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\WINDOWS\System32\OpenSSH\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\SlikSvn\bin;D:\System\Programs\nodejs\;D:\System\Programs\yarn\bin\;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\dotnet\;C:\Users\devappd\AppData\Local\Programs\Python\Launcher\;C:\Users\devappd\scoop\shims;C:\Users\devappd\AppData\Local\Microsoft\WindowsApps;C:\Users\devappd\AppData\Roaming\npm;C:\Users\devappd\AppData\Local\Yarn\bin;C:\Users\devappd\.dotnet\tools
EMSDK = D:/Projects/emscripten/emscripten-build/emsdk-npm/test/emsdk-test
EM_CONFIG = D:\Projects\emscripten\emscripten-build\emsdk-npm\test\emsdk-test\.emscripten
Clearing existing environment variable: EMSDK_PY
'em++' is not recognized as an internal or external command,
operable program or batch file.
      4) should build an example program and output to test/example-build/main.js
    remove()
      √ should remove the entire install directory (4997ms)


  2 passing (3m)
  4 failing

  1) emsdk-npm JavaScript API
       update()
         should write emscripten-releases-tot.txt to the install dir:

      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert(fs.existsSync(testPath))

      + expected - actual

      -false
      +true

      at Context.<anonymous> (test\test.js:62:9)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)

  2) emsdk-npm JavaScript API
       install()
         should write the correct version to upstream/.emsdk_version:
     TypeError [ERR_INVALID_ARG_TYPE]: The "value" argument must be one of type number or string or an instance of Buffer or Uint8Array. Received undefined
      at bidirectionalIndexOf (buffer.js:942:9)
      at Buffer.indexOf (buffer.js:948:10)
      at Buffer.includes (buffer.js:956:15)
      at Context.<anonymous> (test\test.js:88:26)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)

  3) emsdk-npm JavaScript API
       activate()
         should write .emscripten to the install dir:
     TypeError [ERR_INVALID_ARG_TYPE]: The "value" argument must be one of type number or string or an instance of Buffer or Uint8Array. Received undefined
      at bidirectionalIndexOf (buffer.js:942:9)
      at Buffer.indexOf (buffer.js:948:10)
      at Buffer.includes (buffer.js:956:15)
      at Object.getInstalled (src\common.js:104:24)
      at Context.<anonymous> (test\test.js:94:19)
      at processImmediate (internal/timers.js:458:21)

       run()
         should build an example program and output to test/example-build/main.js:
     Error: spawn cd "D:\projects\emscripten\emscripten-build\emsdk-npm\test\emsdk-test" && "D:\projects\emscripten\emscripten-build\emsdk-npm\test\emsdk-test\emsdk_env.bat" && cd "D:\projects\emscripten\emscripten-build\emsdk-npm\test\example-build" &&  ENOENT
      at notFoundError (node_modules\cross-spawn\lib\enoent.js:11:11)
      at verifyENOENT (node_modules\cross-spawn\lib\enoent.js:46:16)
      at ChildProcess.cp.emit (node_modules\cross-spawn\lib\enoent.js:33:19)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)



npm ERR! code ELIFECYCLE
npm ERR! errno 4
npm ERR! [email protected] test: `mocha`
npm ERR! Exit status 4
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\devappd\AppData\Roaming\npm-cache\_logs\2021-08-17T04_44_38_157Z-debug.log

Unknown command '--embedded' given

When I do npm i emscripten-sdk it causes an error:

npm ERR! code 1
npm ERR! path /Users/Jesper/repositories/narrow/www/node_modules/emscripten-sdk
npm ERR! command failed
npm ERR! command sh -c node src/postinstall.js
npm ERR! Already up to date.
npm ERR! Cloning into '/Users/Jesper/repositories/narrow/www/node_modules/emscripten-sdk/emsdk'...
npm ERR! Unknown command '--embedded' given! Type 'emsdk help' to get a list of commands.
npm ERR! /Users/Jesper/repositories/narrow/www/node_modules/cross-spawn-promise/lib/index.js:20
npm ERR!     var _err = new Error(`Exited with status ${code}`);
npm ERR!                ^
npm ERR! 
npm ERR! Error: Exited with status 1
npm ERR!     at closeArgsToError (/Users/Jesper/repositories/narrow/www/node_modules/cross-spawn-promise/lib/index.js:20:16)
npm ERR!     at ChildProcess.<anonymous> (/Users/Jesper/repositories/narrow/www/node_modules/cross-spawn-promise/lib/index.js:76:19)
npm ERR!     at Object.onceWrapper (node:events:485:26)
npm ERR!     at ChildProcess.emit (node:events:378:20)
npm ERR!     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12) {
npm ERR!   exitStatus: 1,
npm ERR!   stdout: null,
npm ERR!   stderr: null
npm ERR! }

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/Jesper/.npm/_logs/2021-03-29T13_26_45_888Z-debug.log

Not really sure why this started happening suddenly. If I remember correctly this was working fine for [email protected] but now it seems broken for that version as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.