This is an automated email from the ASF dual-hosted git repository.

HyukjinKwon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark-connect-rust.git


The following commit(s) were added to refs/heads/master by this push:
     new d31b40ca [SPARK-61587][CONNECT][BUILD] Find the WASM UDF proc macro 
and the doc snippets' dependencies in the build directory layout of Rust 1.100
d31b40ca is described below

commit d31b40ca1e0418a336f71b55a7846346a7e09896
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Fri Nov 13 08:07:24 2026 +0900

    [SPARK-61587][CONNECT][BUILD] Find the WASM UDF proc macro and the doc 
snippets' dependencies in the build directory layout of Rust 1.100
    
    ### What changes were proposed in this pull request?
    
    Rust 1.100.0 (2026-11-09), which CI's `rustup toolchain install stable` now 
installs, changed the layout of cargo's build directory. The artifacts of each 
unit are in a directory of their own, 
`target/<profile>/build/<package>/<hash>/out`, which is also the `OUT_DIR` of a 
build script, and there is no `target/<profile>/deps` any more. Two places 
assumed the old layout:
    
    - `crates/spark-connect-build` (`apache-spark-connect-build`, the 
`build.rs` helper of WASM UDFs) found the `spark_connect_macros` proc-macro 
dylib in `OUT_DIR/../../../deps`. On Rust 1.100 that is 
`target/debug/build/deps`, so it panics: `could not find the 
spark_connect_macros proc-macro dylib in .../target/debug/build/deps`. This 
fails the WASM UDF feature and Rust behavioral e2e jobs, and any user crate 
that calls `embed_wasm_udf` on Rust 1.100.
    - `scripts/check_doc_snippets.py` compiled the doc snippets with `-L 
dependency=target/debug/deps`, so all 52 fail with ``can't find crate for 
`spark_connect_core` ``. This fails the docs job.
    
    The changes:
    - The helper looks for the dylib in `<profile>/deps` (before Rust 1.100), 
and in the `out` directories of the units of `apache-spark-connect-macros` 
(from Rust 1.100). It takes the newest dylib, as before, and also takes the 
`.dll` of Windows, which has no `lib` prefix. A proc-macro dylib is loaded 
without its dependencies, so the wasm build needs only the directory of the 
dylib.
    - The snippet check reads the rlib of `apache-spark-connect`, and the 
directories of its dependencies' artifacts, from `cargo build -p 
apache-spark-connect --message-format=json`, which reports fresh units too. So 
it does not depend on the layout.
    
    ### Why are the changes needed?
    
    CI fails on every pull request and on master since its stable toolchain 
became 1.100.0: master's last green run used 1.99.1. For example, see #577.
    
    ### Does this PR introduce _any_ user-facing change?
    
    Yes. `spark_connect_build::embed_wasm_udf` works on Rust 1.100, where it 
panicked.
    
    ### How was this patch tested?
    
    - With Rust 1.100.0 and with 1.96.0, each with a fresh target directory: 
`examples/wasm-udf-inline` builds and embeds its `.wasm`, and 
`check_doc_snippets.py` compiles all 52 snippets.
    - On Rust 1.100.0: `cargo build -p pyspark-rs` (no warnings), `cargo test 
-p apache-spark-connect --no-run` with and without `wasm-udf`, the lib tests of 
`apache-spark-connect`, `-core` and `-build` (638, 0 and 218 passed), and 
`cargo test --manifest-path tests/wasm-udf/Cargo.toml --no-run`. Its only 
output is a new cargo lint, "unused dependency `spark-connect-macros`", for the 
build-dependency that the helper needs built.
    - `cargo fmt --all --check`, `ruff check` and `ruff format --check`.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Opus 5.5
    
    This pull request and its description were written by Isaac.
    
    Closes #580 from HyukjinKwon/SPARK-61587-rust-1.100.
    
    Authored-by: Hyukjin Kwon <[email protected]>
    Signed-off-by: Hyukjin Kwon <[email protected]>
---
 crates/spark-connect-build/src/lib.rs | 77 +++++++++++++++++++++++++----------
 scripts/check_doc_snippets.py         | 60 ++++++++++++++++++++++-----
 2 files changed, 104 insertions(+), 33 deletions(-)

diff --git a/crates/spark-connect-build/src/lib.rs 
b/crates/spark-connect-build/src/lib.rs
index 0a5b824a..dd7a1fcf 100644
--- a/crates/spark-connect-build/src/lib.rs
+++ b/crates/spark-connect-build/src/lib.rs
@@ -49,19 +49,24 @@ pub fn embed_wasm_udf(src_file: impl AsRef<Path>) -> 
PathBuf {
         .unwrap_or_else(|| "wasm_udf".to_string());
     let wasm_out = out_dir.join(format!("{stem}.wasm"));
 
-    // deps dir: OUT_DIR = target/<profile>/build/<crate>-<hash>/out
-    let deps_dir = out_dir
-        .ancestors()
-        .nth(3)
-        .expect("unexpected OUT_DIR layout")
-        .join("deps");
-    let macro_dylib = find_proc_macro(&deps_dir, 
"spark_connect_macros").unwrap_or_else(|| {
+    let macro_dirs = proc_macro_dirs(&out_dir, "apache-spark-connect-macros");
+    let macro_dylib = find_proc_macro(&macro_dirs, 
"spark_connect_macros").unwrap_or_else(|| {
         panic!(
             "could not find the spark_connect_macros proc-macro dylib in {}. \
              Add `apache-spark-connect-macros` to [build-dependencies].",
-            deps_dir.display()
+            macro_dirs
+                .iter()
+                .map(|dir| dir.display().to_string())
+                .collect::<Vec<_>>()
+                .join(", ")
         )
     });
+    // The directory of the dylib: rustc loads a proc-macro crate as it is, 
without the
+    // dependencies that it was built with, so it needs no other `-L 
dependency=` directory.
+    let deps_dir = macro_dylib
+        .parent()
+        .expect("a file has a parent directory")
+        .to_path_buf();
 
     // The macro's wasm export wrappers reference `crate::spark_wasm_rt` for 
the
     // binary-ABI codec + allocator. Prepend that runtime and compile the
@@ -483,22 +488,50 @@ fn env(key: &str) -> String {
     std::env::var(key).unwrap_or_else(|_| panic!("`{key}` is not set (call 
from a build script)"))
 }
 
-/// Find `lib<name>-<hash>.{dylib,so,dll}` in `deps_dir`, newest first.
-fn find_proc_macro(deps_dir: &Path, name: &str) -> Option<PathBuf> {
-    let prefix = format!("lib{name}-");
+/// The directories where cargo puts the dylib of the proc-macro package 
`package`, a
+/// build-dependency, for the build script whose `OUT_DIR` is `out_dir`, in 
either layout of
+/// cargo's build directory:
+///
+/// * before Rust 1.100, `OUT_DIR` is `<profile>/build/<crate>-<hash>/out`, 
and the artifacts
+///   of all the dependencies are in `<profile>/deps`;
+/// * from Rust 1.100, `OUT_DIR` is `<profile>/build/<package>/<hash>/out`, 
and the artifacts of
+///   each unit are in the `out` directory of that unit, 
`<profile>/build/<package>/<hash>/out`.
+fn proc_macro_dirs(out_dir: &Path, package: &str) -> Vec<PathBuf> {
+    // `<profile>` in the layout before Rust 1.100, and `<profile>/build` in 
the later one.
+    let Some(base) = out_dir.ancestors().nth(3) else {
+        return Vec::new();
+    };
+    let mut dirs = vec![base.join("deps")];
+    if let Ok(units) = std::fs::read_dir(base.join(package)) {
+        let mut units: Vec<PathBuf> = units.flatten().map(|unit| 
unit.path().join("out")).collect();
+        units.sort();
+        dirs.extend(units);
+    }
+    dirs
+}
+
+/// Find `lib<name>-<hash>.{dylib,so}`, or `<name>-<hash>.dll` on Windows, in 
`dirs`: the newest
+/// one, as a rebuild leaves the stale ones.
+fn find_proc_macro(dirs: &[PathBuf], name: &str) -> Option<PathBuf> {
+    let prefixes = [format!("lib{name}-"), format!("{name}-")];
     let mut best: Option<(std::time::SystemTime, PathBuf)> = None;
-    for entry in std::fs::read_dir(deps_dir).ok()?.flatten() {
-        let path = entry.path();
-        let fname = match path.file_name() {
-            Some(f) => f.to_string_lossy().into_owned(),
-            None => continue,
+    for dir in dirs {
+        let Ok(entries) = std::fs::read_dir(dir) else {
+            continue;
         };
-        let is_dylib =
-            fname.ends_with(".dylib") || fname.ends_with(".so") || 
fname.ends_with(".dll");
-        if fname.starts_with(&prefix) && is_dylib {
-            if let Ok(mtime) = entry.metadata().and_then(|m| m.modified()) {
-                if best.as_ref().map(|(t, _)| mtime > *t).unwrap_or(true) {
-                    best = Some((mtime, path));
+        for entry in entries.flatten() {
+            let path = entry.path();
+            let fname = match path.file_name() {
+                Some(f) => f.to_string_lossy().into_owned(),
+                None => continue,
+            };
+            let is_dylib =
+                fname.ends_with(".dylib") || fname.ends_with(".so") || 
fname.ends_with(".dll");
+            if is_dylib && prefixes.iter().any(|prefix| 
fname.starts_with(prefix)) {
+                if let Ok(mtime) = entry.metadata().and_then(|m| m.modified()) 
{
+                    if best.as_ref().map(|(t, _)| mtime > *t).unwrap_or(true) {
+                        best = Some((mtime, path));
+                    }
                 }
             }
         }
diff --git a/scripts/check_doc_snippets.py b/scripts/check_doc_snippets.py
index e15a48ec..793454ec 100644
--- a/scripts/check_doc_snippets.py
+++ b/scripts/check_doc_snippets.py
@@ -43,6 +43,7 @@ Usage:
 """
 
 import glob
+import json
 import re
 import subprocess
 import sys
@@ -50,10 +51,6 @@ import tempfile
 from pathlib import Path
 
 REPO = Path(__file__).resolve().parent.parent
-# cargo places the primary lib without a hash in target/debug; its dependencies
-# (arrow, prost, ...) live in target/debug/deps and are found via -L 
dependency.
-RLIB = REPO / "target" / "debug" / "libspark_connect.rlib"
-DEPS = REPO / "target" / "debug" / "deps"
 
 # ```rust``` (checked) vs ```{.rust .no-run}``` (rendered but skipped). We 
only check
 # plain ```rust``` fences; any info string with a comma/space/brace is left 
alone.
@@ -79,7 +76,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {{
 """
 
 
-def check_block(code: str, tmpdir: Path, idx: int) -> tuple[bool, str]:
+def check_block(
+    code: str, tmpdir: Path, idx: int, rlib: Path, deps: list[Path]
+) -> tuple[bool, str]:
     indented = "\n".join("        " + ln if ln.strip() else ln for ln in 
code.splitlines())
     src = tmpdir / f"snippet_{idx}.rs"
     src.write_text(HARNESS.format(body=indented))
@@ -92,10 +91,9 @@ def check_block(code: str, tmpdir: Path, idx: int) -> 
tuple[bool, str]:
             "--crate-type",
             "bin",
             "--emit=metadata",
-            "-L",
-            f"dependency={DEPS}",
+            *(arg for dep in deps for arg in ("-L", f"dependency={dep}")),
             "--extern",
-            f"spark_connect={RLIB}",
+            f"spark_connect={rlib}",
             "-o",
             str(out),
             str(src),
@@ -106,9 +104,49 @@ def check_block(code: str, tmpdir: Path, idx: int) -> 
tuple[bool, str]:
     return r.returncode == 0, r.stderr
 
 
+def crate_artifacts() -> tuple[Path | None, list[Path]]:
+    """The rlib of ``apache-spark-connect`` and the directories of the 
artifacts of its
+    dependencies (arrow, prost, ...), which rustc finds them in with ``-L 
dependency``, as cargo
+    reports them for ``cargo build -p apache-spark-connect``, of the units 
that are fresh too.
+
+    Cargo's layout of them changed: before Rust 1.100, the artifacts of all 
the dependencies are
+    in ``target/debug/deps``, and from Rust 1.100, those of each unit are in a 
directory of its
+    own, ``target/debug/build/<package>/<hash>/out``.
+    """
+    r = subprocess.run(
+        ["cargo", "build", "-p", "apache-spark-connect", 
"--message-format=json"],
+        cwd=REPO,
+        capture_output=True,
+        text=True,
+    )
+    if r.returncode != 0:
+        print(r.stderr[-4000:])
+        return None, []
+    rlib = None
+    deps: list[Path] = []
+    for line in r.stdout.splitlines():
+        try:
+            msg = json.loads(line)
+        except ValueError:
+            continue
+        if msg.get("reason") != "compiler-artifact":
+            continue
+        for name in msg.get("filenames", []):
+            path = Path(name)
+            if (
+                path.suffix in (".rlib", ".rmeta", ".so", ".dylib", ".dll")
+                and path.parent not in deps
+            ):
+                deps.append(path.parent)
+            if msg.get("target", {}).get("name") == "spark_connect" and 
path.suffix == ".rlib":
+                rlib = path
+    return rlib, deps
+
+
 def main() -> int:
-    if not RLIB.exists():
-        print(f"!! {RLIB} not found - run `cargo build -p 
apache-spark-connect` first")
+    rlib, deps = crate_artifacts()
+    if rlib is None or not rlib.exists():
+        print("!! no rlib of apache-spark-connect - run `cargo build -p 
apache-spark-connect`")
         return 2
 
     failures = []
@@ -121,7 +159,7 @@ def main() -> int:
             for m in _BLOCK.finditer(text):
                 idx += 1
                 checked += 1
-                ok, err = check_block(m.group(1), tmpdir, idx)
+                ok, err = check_block(m.group(1), tmpdir, idx, rlib, deps)
                 if not ok:
                     rel = Path(md).relative_to(REPO)
                     # First rustc error line is the most informative.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to