Skip to content

Commit

Permalink
Refactored wasm and rust workspace, and added jsonpath
Browse files Browse the repository at this point in the history
  • Loading branch information
halvardssm committed Oct 15, 2024
1 parent fae197d commit d1a3e17
Show file tree
Hide file tree
Showing 31 changed files with 23,587 additions and 2,957 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ html_cov/
cov.lcov
coverage/
docs/
crypto/hash/_wasm/target
_wasm/target
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"deno.enable": true,
"deno.unstable": true,
"editor.defaultFormatter": "denoland.vscode-deno"
"deno.unstable": true
}
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ console.log(dump(buffer));
utility for text encoding.
- [http](https://jsr.io/@stdext/http): The http package contains utility for
fetching and http servers
- [json](https://jsr.io/@stdext/json): The json package, contains helpers for
json parsing, querying (jsonpath) and processing
- [lexer](https://jsr.io/@stdext/lexer): The lexer package contains general
purpose lexers/tokenizers
- [types](https://jsr.io/@stdext/types): The types package, contains general
purpose type helpers

## Versioning

Expand All @@ -68,6 +74,21 @@ implemented.
For modules that use Rust to compile to WASM, we allow the usage of third-party
crates if necessary, but this will be considered on a case-by-case basis.

## WASM

All wasm code is generated from the rust workspace in the [\_wasm](./_wasm)
folder.

To generate the wasm code:

```sh
deno task build:wasm
```

This will call the [build_wasm.ts](./_tools/build_wasm.ts) script and will place
each generated lib in its respective package based on its prefix. See script for
more details.

## Deprecation Policy

We follow the
Expand Down
51 changes: 51 additions & 0 deletions _tools/build_wasm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { parse } from "@std/toml";
import { resolve } from "@std/path";

const isCheck = Deno.args.some((a) => a === "--check");
const failFast = Deno.args.some((a) => a === "--fail-fast");

const rawCargo = Deno.readTextFileSync("./_wasm/Cargo.toml");

const parsedCargo = parse(rawCargo) as { workspace: { members: string[] } };

let didFail = false;

for (const member of parsedCargo.workspace.members) {
const [folder] = member.split("_");
const outPath = resolve(
folder,
"_wasm",
);

const args: string[] = [
"run",
"-A",
"jsr:@deno/[email protected]",
"--js-ext",
"mjs",
"--sync",
"--project",
member,
"--out",
outPath,
];

if (isCheck) {
args.push("--check");
}

const command = new Deno.Command(Deno.execPath(), {
args: args,
cwd: "./_wasm",
});
const child = command.spawn();
const status = await child.status;
if (!status.success) {
didFail = true;
}
if (failFast && didFail) {
Deno.exit(1);
}
}

Deno.exit(didFail ? 1 : 0);
File renamed without changes.
180 changes: 177 additions & 3 deletions crypto/hash/_wasm/Cargo.lock → _wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions crypto/hash/_wasm/Cargo.toml → _wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[workspace]
resolver = "2"
members = [
"argon2",
"bcrypt",
"scrypt"
"crypto_hash_argon2",
"crypto_hash_bcrypt",
"crypto_hash_scrypt",
"json_jsonpath"
]

[workspace.package]
Expand All @@ -14,6 +15,8 @@ edition = "2021"
wasm-bindgen = "0.2.92"
serde = { version = "1", features = ["derive"] }
serde-wasm-bindgen = "0.4"
serde_json = "1"
serde_json_path = "0.6"
getrandom = { version = "0.2", features = ["js"] }
rand_core = { version = "0.6", features = ["std"] }
js-sys = "0.3"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "deno_stdext_crypto_hash_wasm_argon2"
name = "crypto_hash_argon2"
version.workspace = true
edition.workspace = true

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "deno_stdext_crypto_hash_wasm_bcrypt"
name = "crypto_hash_bcrypt"
version.workspace = true
edition.workspace = true

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "deno_stdext_crypto_hash_wasm_scrypt"
name = "crypto_hash_scrypt"
version.workspace = true
edition.workspace = true

Expand Down
File renamed without changes.
Loading

0 comments on commit d1a3e17

Please sign in to comment.