Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify Type System packages #808

Merged
merged 21 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/actions/warm-up-repo/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ runs:
node-version: 16 ## aligned with Node version on Vercel
cache: yarn

- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: crates/type-system

- name: Install Cargo-Make
shell: bash
run: |
cargo install cargo-quickinstall
cargo quickinstall cargo-make --version 0.35.15

- run: yarn install
shell: bash
env:
Expand Down
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ apps/site/site-map.json
apps/site/test-results
packages/block-template-html/dev/src
packages/mock-block-dock/src/version.ts
packages/@blockprotocol/type-system/.rollup.cache
packages/@blockprotocol/type-system/wasm

##################
## Specific to git
##################

## Build artifacts that need to be version-controlled
!packages/@blockprotocol/type-system-node/dist
!packages/@blockprotocol/type-system-web/dist
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ apps/site/site-map.json
apps/site/test-results
packages/block-template-html/dev/src
packages/mock-block-dock/src/version.ts
packages/@blockprotocol/type-system/.rollup.cache
packages/@blockprotocol/type-system/wasm
Alfred-Mountfield marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ We welcome [contributions](#contributing) to this repository. Within it you will
- `@blockprotocol/core`: implements the Block Protocol Core specification for blocks and embedding applications
- `@blockprotocol/graph`: implements the Block Protocol Graph specification for blocks and embedding applications
- `@blockprotocol/hook`: implements the Block Protocol Hook service for blocks and embedding applications
- `@blockprotocol/type-system-{node,web}`: implements type system (autogenerated from `crates/type-system`)
- `@blockprotocol/type-system`: implements the type system (with code autogenerated from `crates/type-system`)
- `@local/*`: auxiliary packages for local development and testing
- `block-scripts`: scripts used by `block-template-*`
- `block-template-*`: starter templates for blocks, used by `create-block-app`
Expand Down
9 changes: 6 additions & 3 deletions crates/type-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tsify = "0.4.2"
url = "2.2.2"

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = { version = "0.2.63", features = ["serde-serialize"] }
wasm-bindgen = { version = "0.2.69", features = ["serde-serialize"] }
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
Expand All @@ -30,5 +30,8 @@ console_error_panic_hook = { version = "0.1.6" }
wasm-bindgen-test = "0.3.13"

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"
lto = true
opt-level = 's'

[package.metadata.wasm-pack.profile.release]
wasm-opt = false
11 changes: 5 additions & 6 deletions crates/type-system/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ run_task = { name = ["build", "lint", "test"] }
[tasks.cargo]
private = true
command = "cargo"
dependencies = ["install-cargo-hack"]

[tasks.yarn]
private = true
Expand Down Expand Up @@ -71,7 +70,7 @@ args = ["build", "--profile", "${CARGO_MAKE_CARGO_PROFILE}", "@@split(CARGO_BUIL
extend = "node"
cwd = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}"
args = ["--loader", "ts-node/esm", "./scripts/build-wasm.ts"]
dependencies = ["install-wasm-pack"]
dependencies = ["install-wasm-pack", "install-wasm-opt"]

################################################################################
## Lints ##
Expand Down Expand Up @@ -170,14 +169,14 @@ install_crate = { rustup_component_name = "clippy" }
private = true
install_crate = { rustup_component_name = "rustfmt" }

[tasks.install-cargo-hack]
private = true
install_crate = { crate_name = "cargo-hack", version = "0.5.15", binary = "cargo", test_arg = ["hack", "--version"] }

[tasks.install-cargo-nextest]
private = true
install_crate = { crate_name = "cargo-nextest", version = "0.9.28", binary = "cargo", test_arg = ["nextest", "--version"] }

[tasks.install-wasm-pack]
private = true
install_crate = { crate_name = "wasm-pack", version = "0.10.3", binary = "wasm-pack", test_arg = ["--version"] }

[tasks.install-wasm-opt]
private = true
install_crate = { crate_name = "wasm-opt", version = "0.110.2", binary = "wasm-opt", test_arg = ["--version"] }
5 changes: 2 additions & 3 deletions crates/type-system/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

## Building the Packages

- `cargo make build` - Compiles the Rust crate, and generates the following WASM-based NPM packages
- [@blockprotocol/type-system-web](../../packages/@blockprotocol/type-system-web)
- [@blockprotocol/type-system-node](../../packages/@blockprotocol/type-system-node)
- `cargo make build` - Compiles the Rust crate, and generates the following WASM-based NPM package
- [@blockprotocol/type-system-web](../../packages/@blockprotocol/type-system)

For more granular task control look at `cargo make --list-all-steps`

Expand Down
28 changes: 12 additions & 16 deletions crates/type-system/scripts/build-wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ type PathObject = {
ext: string;
};

const runWasmPack = (target: string) => {
console.log(`Running wasm-pack targeting ${target}`);
const runWasmPack = () => {
console.log(`Running wasm-pack targeting "web"`);
const result = child_process.spawnSync("wasm-pack", [
"build",
"--target",
target,
"web",
"--out-name",
"index",
"type-system",
"--scope",
"blockprotocol",
"--release",
]);

if (result.status !== 0) {
Expand All @@ -35,16 +36,16 @@ const runWasmPack = (target: string) => {
}
};

const moveSrcFiles = (packagePath: PathObject, packageName: string) => {
const moveSrcFiles = (packagePath: PathObject) => {
const destinationPath = path.resolve(
packageDirPath,
"..",
"..",
"..",
"packages",
"@blockprotocol",
packageName,
"dist",
"type-system",
"wasm",
);

console.log(
Expand All @@ -67,18 +68,13 @@ const cleanUp = (packagePath: PathObject) => {
fs.rmSync(path.format(packagePath), { recursive: true });
};

const buildWasmPackage = (packageName: string, target: string) => {
runWasmPack(target);
const buildWasmPackage = () => {
runWasmPack();

const pkgFolderPath = path.parse(path.resolve("./pkg/"));

moveSrcFiles(pkgFolderPath, packageName);
moveSrcFiles(pkgFolderPath);
cleanUp(pkgFolderPath);
};

const buildPackages = () => {
buildWasmPackage("type-system-web", "web");
buildWasmPackage("type-system-node", "nodejs");
};

buildPackages();
buildWasmPackage();
3 changes: 2 additions & 1 deletion crates/type-system/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "@local/tsconfig/node.json"
"extends": "@local/tsconfig/node.json",
"exclude": ["./target/*"]
Alfred-Mountfield marked this conversation as resolved.
Show resolved Hide resolved
}
13 changes: 0 additions & 13 deletions packages/@blockprotocol/type-system-node/CHANGELOG.md

This file was deleted.

24 changes: 0 additions & 24 deletions packages/@blockprotocol/type-system-node/LICENSE.md

This file was deleted.