From e5de316a495f0087ef309ba64e661016c948c7b3 Mon Sep 17 00:00:00 2001 From: OJ Kwon <1210596+kwonoj@users.noreply.github.com> Date: Wed, 5 Jul 2023 11:46:32 -0700 Subject: [PATCH] feat(turbopack): support native webp --- .github/workflows/build_and_deploy.yml | 2 +- Cargo.lock | 37 +++++++++++++++++-- packages/next-swc/crates/napi/Cargo.toml | 1 + packages/next-swc/crates/next-core/Cargo.toml | 2 + packages/next-swc/package.json | 10 ++--- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build_and_deploy.yml b/.github/workflows/build_and_deploy.yml index 927c4c90b46a13..4b292c4e8ce53c 100644 --- a/.github/workflows/build_and_deploy.yml +++ b/.github/workflows/build_and_deploy.yml @@ -143,7 +143,7 @@ jobs: rustup target add aarch64-unknown-linux-gnu && npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" "turbo@${TURBO_VERSION}" && if [ ! -f $(dirname $(which yarn))/pnpm ]; then ln -s $(which yarn) $(dirname $(which yarn))/pnpm;fi && export CC_aarch64_unknown_linux_gnu=/usr/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-gcc && - turbo run build-native-release --remote-cache-timeout 90 --summarize -- --target aarch64-unknown-linux-gnu && + turbo run build-native-release --remote-cache-timeout 90 --summarize -- --target aarch64-unknown-linux-gnu --features plugin,rustls-tls,tracing/release_max_level_info && llvm-strip -x packages/next-swc/native/next-swc.*.node - host: ubuntu-latest target: 'aarch64-unknown-linux-musl' diff --git a/Cargo.lock b/Cargo.lock index 582f457d929dca..f122723abaf26d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -772,6 +772,9 @@ name = "cc" version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +dependencies = [ + "jobserver", +] [[package]] name = "cesu8" @@ -2511,6 +2514,7 @@ dependencies = [ "num-rational", "num-traits", "png", + "webp", ] [[package]] @@ -2700,6 +2704,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" +[[package]] +name = "jobserver" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +dependencies = [ + "libc", +] + [[package]] name = "jpeg-decoder" version = "0.3.0" @@ -2891,6 +2904,15 @@ dependencies = [ "libc", ] +[[package]] +name = "libwebp-sys" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439fd1885aa28937e7edcd68d2e793cb4a22f8733460d2519fbafd2b215672bf" +dependencies = [ + "cc", +] + [[package]] name = "libz-sys" version = "1.1.8" @@ -3245,9 +3267,9 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "napi" -version = "2.12.5" +version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69b29acdc6cc5c918c3eabd51d241b1c6dfa8914f3552fcfd76e1d7536934581" +checksum = "0ede2d12cd6fce44da537a4be1f5510c73be2506c2e32dfaaafd1f36968f3a0e" dependencies = [ "anyhow", "bitflags 2.3.3", @@ -7901,7 +7923,7 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 1.0.0", + "cfg-if 0.1.10", "rand 0.4.6", "static_assertions", ] @@ -8709,6 +8731,15 @@ dependencies = [ "walkdir", ] +[[package]] +name = "webp" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf022f821f166079a407d000ab57e84de020e66ffbbf4edde999bc7d6e371cae" +dependencies = [ + "libwebp-sys", +] + [[package]] name = "webpki" version = "0.22.0" diff --git a/packages/next-swc/crates/napi/Cargo.toml b/packages/next-swc/crates/napi/Cargo.toml index bd573cdf93687e..809ef16bc20247 100644 --- a/packages/next-swc/crates/napi/Cargo.toml +++ b/packages/next-swc/crates/napi/Cargo.toml @@ -20,6 +20,7 @@ sentry_rustls = ["sentry", "sentry/rustls", "rustls-tls"] native-tls = ["next-dev/native-tls"] rustls-tls = ["next-dev/rustls-tls"] serializable = ["next-dev/serializable"] +image-webp = ["next-core/image-webp"] # Enable dhat profiling allocator for heap profiling. __internal_dhat-heap = ["dhat"] diff --git a/packages/next-swc/crates/next-core/Cargo.toml b/packages/next-swc/crates/next-core/Cargo.toml index fae5a56ebffecc..4fbad7580685bd 100644 --- a/packages/next-swc/crates/next-core/Cargo.toml +++ b/packages/next-swc/crates/next-core/Cargo.toml @@ -66,6 +66,8 @@ turbopack-binding = { workspace = true, features = ["__turbo_tasks_build"] } next-font-local = [] native-tls = ["turbopack-binding/__turbo_tasks_fetch_native-tls"] rustls-tls = ["turbopack-binding/__turbo_tasks_fetch_rustls-tls"] +image-webp = ["turbopack-binding/__turbopack_image_webp"] + # enable "HMR" for embedded assets dynamic_embed_contents = [ "turbopack-binding/__turbo_tasks_fs_dynamic_embed_contents", diff --git a/packages/next-swc/package.json b/packages/next-swc/package.json index e61f447fae1a94..c113a6dee8b80c 100644 --- a/packages/next-swc/package.json +++ b/packages/next-swc/package.json @@ -4,11 +4,11 @@ "private": true, "scripts": { "clean": "node ../../scripts/rm.mjs native", - "build-native": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --features plugin,rustls-tls --js false native", - "build-native-release": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --release --features plugin,rustls-tls,tracing/release_max_level_info --js false native", - "build-native-no-plugin": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --js false native", - "build-native-no-plugin-woa": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --cargo-flags=--no-default-features --features native-tls --js false native", - "build-native-no-plugin-woa-release": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --release --cargo-flags=--no-default-features --features native-tls,tracing/release_max_level_info --js false native", + "build-native": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --features plugin,rustls-tls,image-webp --js false native", + "build-native-release": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --release --features plugin,rustls-tls,image-webp,tracing/release_max_level_info --js false native", + "build-native-no-plugin": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --features image-webp --js false native", + "build-native-no-plugin-woa": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --cargo-flags=--no-default-features --features native-tls,image-webp --js false native", + "build-native-no-plugin-woa-release": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --release --cargo-flags=--no-default-features --features native-tls,image-webp,tracing/release_max_level_info --js false native", "build-wasm": "wasm-pack build crates/wasm --scope=next", "cache-build-native": "echo $(ls native)", "rust-check": "cd ../../; cargo fmt -- --check && cargo clippy --all -- -D warnings -A deprecated && cargo check -p next-dev --no-default-features --features cli,custom_allocator,rustls-tls,serializable && rm -rf target",