Repository: risingwavelabs/risingwave (language: rust)

Issue:
cherry-pick fix(udf): fix wasm e2e test compile and update build target (#20623) to branch release-2.1
Cherry picking \#20623 onto branch release-2.1,

This PR/issue was created by cherry-pick action from commit 1c459aa6be64748e9b21c6e8fbc2365ad21e8f90.,


Discussion / hints:

Fix patch:
diff --git a/Cargo.lock b/Cargo.lock
index 23bedab0e0f13..816a2606998cf 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2577,9 +2577,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
 
 [[package]]
 name = "chrono"
-version = "0.4.38"
+version = "0.4.39"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
+checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825"
 dependencies = [
  "android-tzdata",
  "iana-time-zone",
diff --git a/ci/Dockerfile b/ci/Dockerfile
index 95dbb5205c754..127f05722410e 100644
--- a/ci/Dockerfile
+++ b/ci/Dockerfile
@@ -42,7 +42,7 @@ ENV PATH /root/.cargo/bin/:$PATH
 RUN rustup show && \
     rustup default `rustup show active-toolchain | awk '{print $1}'` && \
     rustup component add rustfmt llvm-tools-preview clippy && \
-    rustup target add wasm32-wasi
+    rustup target add wasm32-wasip1
 
 RUN curl -sSL "https://github.com/bufbuild/buf/releases/download/v1.29.0/buf-$(uname -s)-$(uname -m).tar.gz" | \
     tar -xvzf - -C /usr/local --strip-components 1
diff --git a/ci/scripts/build-other.sh b/ci/scripts/build-other.sh
index 70adf10a8f7fd..0c9f206892ade 100755
--- a/ci/scripts/build-other.sh
+++ b/ci/scripts/build-other.sh
@@ -7,8 +7,8 @@ source ci/scripts/common.sh
 
 echo "--- Build Rust UDF"
 cd e2e_test/udf/wasm
-rustup target add wasm32-wasi
-cargo build --release --target wasm32-wasi
+rustup target add wasm32-wasip1
+cargo build --release --target wasm32-wasip1
 cd ../../..
 
 echo "--- Build Java packages"
@@ -35,7 +35,7 @@ tar --zstd -cf java-binding-integration-test.tar.zst bin java/java-binding-integ
 echo "--- Upload Java artifacts"
 cp java/connector-node/assembly/target/risingwave-connector-1.0.0.tar.gz ./risingwave-connector.tar.gz
 cp e2e_test/udf/java/target/risingwave-udf-example.jar ./udf.jar
-cp e2e_test/udf/wasm/target/wasm32-wasi/release/udf.wasm udf.wasm
+cp e2e_test/udf/wasm/target/wasm32-wasip1/release/udf.wasm udf.wasm
 buildkite-agent artifact upload ./risingwave-connector.tar.gz
 buildkite-agent artifact upload ./java-binding-integration-test.tar.zst
 buildkite-agent artifact upload ./udf.jar
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 626611345fd61..af913be5ff985 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -31,7 +31,7 @@ RUN rustup self update \
   && rustup set profile minimal \
   && rustup show \
   && rustup component add rustfmt \
-  && rustup target add wasm32-wasi
+  && rustup target add wasm32-wasip1
 
 RUN cargo install flamegraph
 RUN cargo install addr2line --features bin --bin addr2line
diff --git a/docker/Dockerfile.hdfs b/docker/Dockerfile.hdfs
index ca967b41d0850..44743620d16f3 100644
--- a/docker/Dockerfile.hdfs
+++ b/docker/Dockerfile.hdfs
@@ -90,7 +90,7 @@ RUN rustup self update \
   && rustup set profile minimal \
   && rustup show \
   && rustup component add rustfmt \
-  && rustup target add wasm32-wasi
+  && rustup target add wasm32-wasip1
 
 RUN cargo fetch
 
diff --git a/src/expr/impl/Cargo.toml b/src/expr/impl/Cargo.toml
index 33c41c09515a5..0bb530033b676 100644
--- a/src/expr/impl/Cargo.toml
+++ b/src/expr/impl/Cargo.toml
@@ -32,6 +32,7 @@ arrow-udf-wasm = { workspace = true, optional = true }
 async-trait = "0.1"
 auto_enums = { workspace = true }
 bytes = "1"
+# The feature setting is also used in src/expr/impl/src/udf/wasm.rs
 chrono = { version = "0.4", default-features = false, features = [
     "clock",
     "std",
diff --git a/src/expr/impl/src/udf/wasm.rs b/src/expr/impl/src/udf/wasm.rs
index 90e7f6e11288f..298b00bdabef8 100644
--- a/src/expr/impl/src/udf/wasm.rs
+++ b/src/expr/impl/src/udf/wasm.rs
@@ -92,7 +92,18 @@ fn create_rust(opts: CreateFunctionOptions<'_>) -> Result<CreateFunctionOutput>
 
     let wasm_binary = std::thread::spawn(move || {
         let mut opts = arrow_udf_wasm::build::BuildOpts::default();
-        opts.arrow_udf_version = Some("0.5".to_string());
+        // Use the same chrono feature setting as src/expr/impl/Cargo.toml
+        // Use a fixed chrono version 0.4.39 because the latest 0.4.40 failed to compile.
+        // TODO: may avoid setting a fixed version when succeed to compile with latest chrono version
+        opts.manifest = r#"
+[dependencies]
+chrono = { version = "=0.4.39", default-features = false, features = [
+    "clock",
+    "std",
+] }
+"#
+        .to_owned();
+        opts.arrow_udf_version = Some("0.5".to_owned());
         opts.script = script;
         // use a fixed tempdir to reuse the build cache
         opts.tempdir = Some(std::env::temp_dir().join("risingwave-rust-udf"));


Test patch:
diff --git a/ci/scripts/slow-e2e-test.sh b/ci/scripts/slow-e2e-test.sh
index dc33c2719053b..6b59b962a875a 100755
--- a/ci/scripts/slow-e2e-test.sh
+++ b/ci/scripts/slow-e2e-test.sh
@@ -28,8 +28,8 @@ download_and_prepare_rw "$profile" common
 
 
 echo "--- Download artifacts"
-mkdir -p e2e_test/udf/wasm/target/wasm32-wasi/release/
-buildkite-agent artifact download udf.wasm e2e_test/udf/wasm/target/wasm32-wasi/release/
+mkdir -p e2e_test/udf/wasm/target/wasm32-wasip1/release/
+buildkite-agent artifact download udf.wasm e2e_test/udf/wasm/target/wasm32-wasip1/release/
 buildkite-agent artifact download udf.jar ./
 
 echo "--- e2e, $mode, slow-udf-tests"
diff --git a/e2e_test/udf/wasm/.cargo/config.toml b/e2e_test/udf/wasm/.cargo/config.toml
index 6b77899cb3333..6b509f5b7024d 100644
--- a/e2e_test/udf/wasm/.cargo/config.toml
+++ b/e2e_test/udf/wasm/.cargo/config.toml
@@ -1,2 +1,2 @@
 [build]
-target = "wasm32-wasi"
+target = "wasm32-wasip1"
diff --git a/e2e_test/udf/wasm/Cargo.toml b/e2e_test/udf/wasm/Cargo.toml
index ce957389ca314..8adac83e2c0e5 100644
--- a/e2e_test/udf/wasm/Cargo.toml
+++ b/e2e_test/udf/wasm/Cargo.toml
@@ -9,6 +9,12 @@ crate-type = ["cdylib"]
 
 [dependencies]
 arrow-udf = "0.5"
+#using a fixed chrono version 0.4.39 because the
+#latest 0.4.40 failed to compile
+chrono = "=0.4.39"
 genawaiter = "0.99"
 rust_decimal = "1"
 serde_json = "1"
+
+[package.metadata.cargo-machete]
+ignored = ["chrono"]
diff --git a/e2e_test/udf/wasm_udf.slt b/e2e_test/udf/wasm_udf.slt
index d182e8ff0f993..041c1c14a16bc 100644
--- a/e2e_test/udf/wasm_udf.slt
+++ b/e2e_test/udf/wasm_udf.slt
@@ -3,31 +3,31 @@
 
 statement ok
 create function int_42() returns int
-language wasm using link 'fs://e2e_test/udf/wasm/target/wasm32-wasi/release/udf.wasm';
+language wasm using link 'fs://e2e_test/udf/wasm/target/wasm32-wasip1/release/udf.wasm';
 
 statement ok
 create function gcd(int, int) returns int
-language wasm using link 'fs://e2e_test/udf/wasm/target/wasm32-wasi/release/udf.wasm';
+language wasm using link 'fs://e2e_test/udf/wasm/target/wasm32-wasip1/release/udf.wasm';
 
 statement ok
 create function gcd(int, int, int) returns int
-language wasm using link 'fs://e2e_test/udf/wasm/target/wasm32-wasi/release/udf.wasm';
+language wasm using link 'fs://e2e_test/udf/wasm/target/wasm32-wasip1/release/udf.wasm';
 
 statement ok
 create function extract_tcp_info(bytea) returns struct<src_addr varchar, dst_addr varchar, src_port smallint, dst_port smallint>
-language wasm using link 'fs://e2e_test/udf/wasm/target/wasm32-wasi/release/udf.wasm';
+language wasm using link 'fs://e2e_test/udf/wasm/target/wasm32-wasip1/release/udf.wasm';
 
 statement ok
 create function decimal_add(decimal, decimal) returns decimal
-language wasm using link 'fs://e2e_test/udf/wasm/target/wasm32-wasi/release/udf.wasm';
+language wasm using link 'fs://e2e_test/udf/wasm/target/wasm32-wasip1/release/udf.wasm';
 
 statement ok
 create function jsonb_access(jsonb, int) returns jsonb
-language wasm using link 'fs://e2e_test/udf/wasm/target/wasm32-wasi/release/udf.wasm';
+language wasm using link 'fs://e2e_test/udf/wasm/target/wasm32-wasip1/release/udf.wasm';
 
 statement ok
 create function series(int) returns table (x int)
-language wasm using link 'fs://e2e_test/udf/wasm/target/wasm32-wasi/release/udf.wasm';
+language wasm using link 'fs://e2e_test/udf/wasm/target/wasm32-wasip1/release/udf.wasm';
 
 query I
 select int_42();