@samitouri / QOS-React-1 / commits / 7fc7488ac8

[rust] Scaffolding for napi-backed npm package

Scaffolds out a `forget_napi` crate following the guide for https://napi.rs/. This crate will be the public JS api for interacting with Forget.

Joe Savona committed Aug 21, 2023 at 14:51 UTC 7fc7488ac8a43de35ca7ca7cc849e99d040961fe
6 files changed +229 -6
compiler/forget/Cargo.lock
+160 -6
@@ -88,6 +88,12 @@ version = "1.3.2"
88 source = "registry+https://github.com/rust-lang/crates.io-index"
89 checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
90
91 +[[package]]
92 +name = "bitflags"
93 +version = "2.4.0"
94 +source = "registry+https://github.com/rust-lang/crates.io-index"
95 +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
96 +
97 [[package]]
98 name = "bstr"
99 version = "1.5.0"
@@ -131,6 +137,25 @@ dependencies = [
137 "windows-sys 0.45.0",
138 ]
139
140 +[[package]]
141 +name = "convert_case"
142 +version = "0.6.0"
143 +source = "registry+https://github.com/rust-lang/crates.io-index"
144 +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca"
145 +dependencies = [
146 + "unicode-segmentation",
147 +]
148 +
149 +[[package]]
150 +name = "ctor"
151 +version = "0.2.4"
152 +source = "registry+https://github.com/rust-lang/crates.io-index"
153 +checksum = "1f34ba9a9bcb8645379e9de8cb3ecfcf4d1c85ba66d90deb3259206fa5aa193b"
154 +dependencies = [
155 + "quote",
156 + "syn 2.0.23",
157 +]
158 +
159 [[package]]
160 name = "encode_unicode"
161 version = "0.3.6"
@@ -212,7 +237,7 @@ dependencies = [
237 "quote",
238 "serde",
239 "serde_json",
215 - "syn",
240 + "syn 2.0.23",
241 ]
242
243 [[package]]
@@ -256,6 +281,15 @@ dependencies = [
281 "thiserror",
282 ]
283
284 +[[package]]
285 +name = "forget_napi"
286 +version = "0.1.0"
287 +dependencies = [
288 + "napi",
289 + "napi-build",
290 + "napi-derive",
291 +]
292 +
293 [[package]]
294 name = "forget_optimization"
295 version = "0.1.0"
@@ -484,6 +518,16 @@ name = "libcplusplus"
518 version = "0.1.0"
519 source = "git+https://github.com/facebook/hermes.git#b2618410b4093e780a04228a2ce87a3626983506"
520
521 +[[package]]
522 +name = "libloading"
523 +version = "0.7.4"
524 +source = "registry+https://github.com/rust-lang/crates.io-index"
525 +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
526 +dependencies = [
527 + "cfg-if",
528 + "winapi",
529 +]
530 +
531 [[package]]
532 name = "linked-hash-map"
533 version = "0.5.6"
@@ -537,7 +581,7 @@ checksum = "4901771e1d44ddb37964565c654a3223ba41a594d02b8da471cc4464912b5cfa"
581 dependencies = [
582 "proc-macro2",
583 "quote",
540 - "syn",
584 + "syn 2.0.23",
585 ]
586
587 [[package]]
@@ -549,6 +593,76 @@ dependencies = [
593 "adler",
594 ]
595
596 +[[package]]
597 +name = "napi"
598 +version = "2.13.3"
599 +source = "registry+https://github.com/rust-lang/crates.io-index"
600 +checksum = "fd063c93b900149304e3ba96ce5bf210cd4f81ef5eb80ded0d100df3e85a3ac0"
601 +dependencies = [
602 + "bitflags 2.4.0",
603 + "ctor",
604 + "napi-derive",
605 + "napi-sys",
606 + "once_cell",
607 + "serde",
608 + "serde_json",
609 + "tokio",
610 +]
611 +
612 +[[package]]
613 +name = "napi-build"
614 +version = "2.0.1"
615 +source = "registry+https://github.com/rust-lang/crates.io-index"
616 +checksum = "882a73d9ef23e8dc2ebbffb6a6ae2ef467c0f18ac10711e4cc59c5485d41df0e"
617 +
618 +[[package]]
619 +name = "napi-derive"
620 +version = "2.13.0"
621 +source = "registry+https://github.com/rust-lang/crates.io-index"
622 +checksum = "da1c6a8fa84d549aa8708fcd062372bf8ec6e849de39016ab921067d21bde367"
623 +dependencies = [
624 + "cfg-if",
625 + "convert_case",
626 + "napi-derive-backend",
627 + "proc-macro2",
628 + "quote",
629 + "syn 1.0.109",
630 +]
631 +
632 +[[package]]
633 +name = "napi-derive-backend"
634 +version = "1.0.52"
635 +source = "registry+https://github.com/rust-lang/crates.io-index"
636 +checksum = "20bbc7c69168d06a848f925ec5f0e0997f98e8c8d4f2cc30157f0da51c009e17"
637 +dependencies = [
638 + "convert_case",
639 + "once_cell",
640 + "proc-macro2",
641 + "quote",
642 + "regex",
643 + "semver",
644 + "syn 1.0.109",
645 +]
646 +
647 +[[package]]
648 +name = "napi-sys"
649 +version = "2.2.3"
650 +source = "registry+https://github.com/rust-lang/crates.io-index"
651 +checksum = "166b5ef52a3ab5575047a9fe8d4a030cdd0f63c96f071cd6907674453b07bae3"
652 +dependencies = [
653 + "libloading",
654 +]
655 +
656 +[[package]]
657 +name = "num_cpus"
658 +version = "1.16.0"
659 +source = "registry+https://github.com/rust-lang/crates.io-index"
660 +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
661 +dependencies = [
662 + "hermit-abi",
663 + "libc",
664 +]
665 +
666 [[package]]
667 name = "object"
668 version = "0.31.1"
@@ -576,6 +690,12 @@ version = "2.3.0"
690 source = "registry+https://github.com/rust-lang/crates.io-index"
691 checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
692
693 +[[package]]
694 +name = "pin-project-lite"
695 +version = "0.2.12"
696 +source = "registry+https://github.com/rust-lang/crates.io-index"
697 +checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05"
698 +
699 [[package]]
700 name = "prettyplease"
701 version = "0.2.10"
@@ -583,7 +703,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
703 checksum = "92139198957b410250d43fad93e630d956499a625c527eda65175c8680f83387"
704 dependencies = [
705 "proc-macro2",
586 - "syn",
706 + "syn 2.0.23",
707 ]
708
709 [[package]]
@@ -642,7 +762,7 @@ version = "0.37.22"
762 source = "registry+https://github.com/rust-lang/crates.io-index"
763 checksum = "8818fa822adcc98b18fedbb3632a6a33213c070556b5aa7c4c8cc21cff565c4c"
764 dependencies = [
645 - "bitflags",
765 + "bitflags 1.3.2",
766 "errno",
767 "io-lifetimes",
768 "libc",
@@ -665,6 +785,12 @@ dependencies = [
785 "winapi-util",
786 ]
787
788 +[[package]]
789 +name = "semver"
790 +version = "1.0.18"
791 +source = "registry+https://github.com/rust-lang/crates.io-index"
792 +checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
793 +
794 [[package]]
795 name = "serde"
796 version = "1.0.167"
@@ -682,7 +808,7 @@ checksum = "b69b106b68bc8054f0e974e70d19984040f8a5cf9215ca82626ea4853f82c4b9"
808 dependencies = [
809 "proc-macro2",
810 "quote",
685 - "syn",
811 + "syn 2.0.23",
812 ]
813
814 [[package]]
@@ -755,6 +881,17 @@ dependencies = [
881 "is-terminal",
882 ]
883
884 +[[package]]
885 +name = "syn"
886 +version = "1.0.109"
887 +source = "registry+https://github.com/rust-lang/crates.io-index"
888 +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
889 +dependencies = [
890 + "proc-macro2",
891 + "quote",
892 + "unicode-ident",
893 +]
894 +
895 [[package]]
896 name = "syn"
897 version = "2.0.23"
@@ -804,7 +941,7 @@ checksum = "d14928354b01c4d6a4f0e549069adef399a284e7995c7ccca94e8a07a5346c59"
941 dependencies = [
942 "proc-macro2",
943 "quote",
807 - "syn",
944 + "syn 2.0.23",
945 ]
946
947 [[package]]
@@ -822,6 +959,17 @@ version = "0.1.1"
959 source = "registry+https://github.com/rust-lang/crates.io-index"
960 checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
961
962 +[[package]]
963 +name = "tokio"
964 +version = "1.32.0"
965 +source = "registry+https://github.com/rust-lang/crates.io-index"
966 +checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9"
967 +dependencies = [
968 + "backtrace",
969 + "num_cpus",
970 + "pin-project-lite",
971 +]
972 +
973 [[package]]
974 name = "unicode-bidi"
975 version = "0.3.13"
@@ -853,6 +1001,12 @@ dependencies = [
1001 "tinyvec",
1002 ]
1003
1004 +[[package]]
1005 +name = "unicode-segmentation"
1006 +version = "1.10.1"
1007 +source = "registry+https://github.com/rust-lang/crates.io-index"
1008 +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
1009 +
1010 [[package]]
1011 name = "unicode-width"
1012 version = "0.1.10"
compiler/forget/crates/forget_napi/Cargo.toml new
+21
@@ -0,0 +1,21 @@
1 +[package]
2 +name = "forget_napi"
3 +version = "0.1.0"
4 +publish = false
5 +authors.workspace = true
6 +description.workspace = true
7 +edition.workspace = true
8 +homepage.workspace = true
9 +keywords.workspace = true
10 +license.workspace = true
11 +repository.workspace = true
12 +
13 +[lib]
14 +crate-type = ["cdylib"]
15 +
16 +[dependencies]
17 +napi = { version = "2.13.3", features = ["serde-json", "async"] }
18 +napi-derive = { version = "2.12" }
19 +
20 +[build-dependencies]
21 +napi-build = "2"
\ No newline at end of file
compiler/forget/crates/forget_napi/build.rs new
+3
@@ -0,0 +1,3 @@
1 +fn main() {
2 + napi_build::setup();
3 +}
compiler/forget/crates/forget_napi/package.json new
+20
@@ -0,0 +1,20 @@
1 +{
2 + "name": "@react/forget-napi",
3 + "version": "0.0.1",
4 + "description": "JavaScript package exposing parts of React Forget compiler APIs via napi",
5 + "main": "dist/index.js",
6 + "license": "MIT",
7 + "files": [
8 + "src"
9 + ],
10 + "private": true,
11 + "scripts": {
12 + "build": "napi build --platform --release --js-package-name @react/forget-napi --js dist/index.js --dts dist/index.d.ts && mv *.node dist/"
13 + },
14 + "dependencies": {
15 + },
16 + "devDependencies": {
17 + "@napi-rs/cli": "^2.15.2"
18 + }
19 + }
20 +
\ No newline at end of file
compiler/forget/crates/forget_napi/src/lib.rs new
+17
@@ -0,0 +1,17 @@
1 +use napi_derive::napi;
2 +
3 +#[napi]
4 +pub fn add(left: i32, right: i32) -> i32 {
5 + left + right
6 +}
7 +
8 +#[cfg(test)]
9 +mod tests {
10 + use super::*;
11 +
12 + #[test]
13 + fn it_works() {
14 + let result = add(2, 2);
15 + assert_eq!(result, 4);
16 + }
17 +}
compiler/forget/crates/forget_napi/yarn.lock new
+8
@@ -0,0 +1,8 @@
1 +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2 +# yarn lockfile v1
3 +
4 +
5 +"@napi-rs/cli@^2.15.2":
6 + version "2.16.3"
7 + resolved "https://registry.yarnpkg.com/@napi-rs/cli/-/cli-2.16.3.tgz#6943d0614bbb4900a97b18ae074f735864f78c4b"
8 + integrity sha512-3mLNPlbbOhpbIUKicLrJtIearlHXUuXL3UeueYyRRplpVMNkdn8xCyzY6PcYZi3JXR8bmCOiWgkVmLnrSL7DKw==