From 1df678c384a096f650489a1c4366312257ce4d37 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 19 Sep 2024 02:11:33 +0000 Subject: [PATCH] Auto-generated commit --- CHANGELOG.md | 3 ++- CONTRIBUTORS | 2 ++ dist/index.js | 2 +- lib/binary.browser.js | 33 +++++++++++++++++++++++ package.json | 7 +++++ scripts/build.js | 63 +++++++++++++++++++++++++++++++++++++++++++ scripts/template.txt | 33 +++++++++++++++++++++++ src/Makefile | 21 ++++++++++++++- 8 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 lib/binary.browser.js create mode 100644 scripts/build.js create mode 100644 scripts/template.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index b006185..9ed720e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@
-## Unreleased (2024-09-16) +## Unreleased (2024-09-19)
@@ -22,6 +22,7 @@
+- [`6e5b8a1`](https://github.com/stdlib-js/stdlib/commit/6e5b8a1747929bc984c994b62faefb1fe96ff5f0) - **build:** add support for generating a base64-encoded Wasm module string _(by Athan Reines)_ - [`07a6dc1`](https://github.com/stdlib-js/stdlib/commit/07a6dc162582bc72e783e3e14e741d08b4a59170) - **test:** update messages _(by Athan Reines)_ - [`ef9e5f6`](https://github.com/stdlib-js/stdlib/commit/ef9e5f6b73e787d500c555f68b705c789d552846) - **style:** disable lint rule _(by Athan Reines)_ - [`8f29918`](https://github.com/stdlib-js/stdlib/commit/8f29918bc72b0634716eede69449d61ed28dd06c) - **feat:** add `blas/base/daxpy-wasm` _(by Athan Reines)_ diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 8610d91..147a89e 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -2,6 +2,7 @@ # # Contributors listed in alphabetical order. +Aayush Khanna <96649223+aayush0325@users.noreply.github.com> Adarsh Palaskar Aditya Sapra AgPriyanshu18 <113460573+AgPriyanshu18@users.noreply.github.com> @@ -39,6 +40,7 @@ Joey Reed Jordan Gallivan <115050475+Jordan-Gallivan@users.noreply.github.com> Joris Labie Justin Dennison +Kaif Mohd Karthik Prakash <116057817+skoriop@users.noreply.github.com> Khaldon Krishnendu Das <86651039+itskdhere@users.noreply.github.com> diff --git a/dist/index.js b/dist/index.js index f6cfb09..05bc70e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,7 +1,7 @@ "use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=y(function(K,h){ var B=require("path").resolve,V=require('@stdlib/fs-read-wasm/dist').sync,g=V(B(__dirname,"..","src","main.wasm"));h.exports=g });var q=y(function(Q,M){ -var j=require('@stdlib/assert-is-wasm-memory/dist'),m=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),z=require('@stdlib/utils-inherit/dist'),w=require('@stdlib/wasm-module-wrapper/dist'),D=require('@stdlib/error-tools-fmtprodmsg/dist'),L=x();function o(e){if(!(this instanceof o))return new o(e);if(!j(e))throw new TypeError(D("invalid argument. Must provide a WebAssembly memory instance. Value: `%s`.",e));return w.call(this,L,e,{env:{memory:e}}),this}z(o,w);m(o.prototype,"main",function(r,s,u,i,a,t){return this._instance.exports.c_daxpy(r,s,u,i,a,t),a});m(o.prototype,"ndarray",function(r,s,u,i,a,t,v,d){return this._instance.exports.c_daxpy_ndarray(r,s,u,i,a,t,v,d),t});M.exports=o +var j=require('@stdlib/assert-is-wasm-memory/dist'),m=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),z=require('@stdlib/utils-inherit/dist'),w=require('@stdlib/wasm-module-wrapper/dist'),D=require('@stdlib/error-tools-fmtprodmsg/dist'),L=x();function o(e){if(!(this instanceof o))return new o(e);if(!j(e))throw new TypeError(D('201H0',e));return w.call(this,L,e,{env:{memory:e}}),this}z(o,w);m(o.prototype,"main",function(r,s,u,i,a,t){return this._instance.exports.c_daxpy(r,s,u,i,a,t),a});m(o.prototype,"ndarray",function(r,s,u,i,a,t,v,d){return this._instance.exports.c_daxpy_ndarray(r,s,u,i,a,t,v,d),t});M.exports=o });var W=y(function(U,b){ var R=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),P=require('@stdlib/utils-inherit/dist'),_=require('@stdlib/strided-base-stride2offset/dist'),k=require('@stdlib/strided-base-read-dataview/dist').ndarray,C=require('@stdlib/wasm-memory/dist'),F=require('@stdlib/wasm-base-arrays2ptrs/dist'),E=require('@stdlib/wasm-base-strided2object/dist'),f=q();function p(){return this instanceof p?(f.call(this,new C({initial:0})),this):new p}P(p,f);R(p.prototype,"main",function(r,s,u,i,a,t){return this.ndarray(r,s,u,i,_(r,i),a,t,_(r,t))});R(p.prototype,"ndarray",function(r,s,u,i,a,t,v,d){var l,c,n;return l=F(this,[E(r,u,i,a),E(r,t,v,d)]),c=l[0],n=l[1],f.prototype.ndarray.call(this,r,s,c.ptr,c.stride,c.offset,n.ptr,n.stride,n.offset),n.copy&&k(r,this.view,n.stride*n.BYTES_PER_ELEMENT,n.ptr,t,v,d,!0),t});b.exports=p });var S=y(function(Z,O){ diff --git a/lib/binary.browser.js b/lib/binary.browser.js new file mode 100644 index 0000000..bc08e05 --- /dev/null +++ b/lib/binary.browser.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var base64ToUint8Array = require( '@stdlib/string-base-base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( 'AGFzbQEAAAAADwhkeWxpbmsuMAEEAAAAAAEYA2AAAGAGf3x/f39/AGAIf3x/f39/f38AAg8BA2VudgZtZW1vcnkCAAADBAMAAQIHTAQRX193YXNtX2NhbGxfY3RvcnMAABhfX3dhc21fYXBwbHlfZGF0YV9yZWxvY3MAAAdjX2RheHB5AAEPY19kYXhweV9uZGFycmF5AAIKmAIDAwABCz0BAn4gACABIAIgAyADrCIGQgEgAKwiB31+QgAgBkIAVxunIAQgBSAFrCIGQgEgB31+QgAgBkIAVxunEAIL0wEBBX8CQCAAQQBMDQAgAUQAAAAAAAAAAGENACAAQQFxIQkgAEEBRwRAIABB/v///wdxIQogBiAGaiELIAMgA2ohDEEAIQADQCAFIAdBA3RqIgggASACIARBA3RqKwMAoiAIKwMAoDkDACAFIAYgB2pBA3RqIgggASACIAMgBGpBA3RqKwMAoiAIKwMAoDkDACAHIAtqIQcgBCAMaiEEIABBAmoiACAKRw0ACwsgCUUNACAFIAdBA3RqIgAgASACIARBA3RqKwMAoiAAKwMAoDkDAAsL' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/package.json b/package.json index 2c6fca4..9d4cb45 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,9 @@ } ], "main": "./lib", + "browser": { + "./lib/binary.js": "./lib/binary.browser.js" + }, "directories": { "benchmark": "./benchmark", "doc": "./docs", @@ -58,10 +61,14 @@ "@stdlib/array-ones": "^0.2.1", "@stdlib/array-zeros": "^0.2.2", "@stdlib/assert-has-wasm-support": "^0.2.2", + "@stdlib/fs-read-file": "^0.2.2", + "@stdlib/fs-write-file": "^0.2.2", "@stdlib/math-base-assert-is-nan": "^0.2.2", "@stdlib/math-base-special-pow": "^0.3.0", "@stdlib/ndarray-base-bytes-per-element": "^0.2.2", "@stdlib/random-array-uniform": "^0.2.1", + "@stdlib/string-base-base64-to-uint8array": "github:stdlib-js/string-base-base64-to-uint8array#main", + "@stdlib/string-replace": "^0.2.2", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", "tap-min": "git+https://github.com/Planeshifter/tap-min.git", diff --git a/scripts/build.js b/scripts/build.js new file mode 100644 index 0000000..388bd65 --- /dev/null +++ b/scripts/build.js @@ -0,0 +1,63 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var readFile = require( '@stdlib/fs-read-file' ).sync; +var writeFile = require( '@stdlib/fs-write-file' ).sync; +var replace = require( '@stdlib/string-replace' ); + + +// VARIABLES // + +var wpath = resolve( __dirname, '..', 'src', 'main.wasm' ); +var tpath = resolve( __dirname, 'template.txt' ); +var opath = resolve( __dirname, '..', 'lib', 'binary.browser.js' ); + +var opts = { + 'encoding': 'utf8' +}; + +var PLACEHOLDER = '{{WASM_BASE64}}'; + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var wasm; + var tmpl; + + wasm = readFile( wpath ); + tmpl = readFile( tpath, opts ); + + tmpl = replace( tmpl, PLACEHOLDER, wasm.toString( 'base64' ) ); + + writeFile( opath, tmpl, opts ); +} + +main(); diff --git a/scripts/template.txt b/scripts/template.txt new file mode 100644 index 0000000..12996dd --- /dev/null +++ b/scripts/template.txt @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( '{{WASM_BASE64}}' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/src/Makefile b/src/Makefile index da6368a..1dd6131 100644 --- a/src/Makefile +++ b/src/Makefile @@ -73,6 +73,13 @@ else WASM_TO_JS := wasm2js endif +# Define the path to the Node.js executable: +ifdef NODE + NODEJS := $(NODE) +else + NODEJS := node +endif + # Define the command-line options when compiling C files: CFLAGS ?= \ -std=c99 \ @@ -115,6 +122,9 @@ wat_targets := main.wat # List of WebAssembly JavaScript targets: wasm_js_targets := main.wasm.js +# List of other JavaScript targets: +browser_js_targets := ./../lib/binary.browser.js + # RULES # @@ -155,7 +165,7 @@ all: wasm # @example # make wasm #/ -wasm: $(wasm_targets) $(wat_targets) +wasm: $(wasm_targets) $(wat_targets) $(browser_js_targets) .PHONY: wasm @@ -191,6 +201,15 @@ $(wat_targets): %.wat: %.wasm $(wasm_js_targets): %.wasm.js: %.wasm $(QUIET) $(WASM_TO_JS) -o $@ $(wasm_targets) +#/ +# Generates an inline WebAssembly build for use in bundlers. +# +# @private +# @param {string} NODE - Node.js executable +#/ +$(browser_js_targets): $(wasm_targets) + $(QUIET) $(NODEJS) ./../scripts/build.js + #/ # Removes generated WebAssembly files. #