Skip to content

Commit 5f233e3

Browse files
committed
Bump Substrait, bake Substrait version into binaries
1 parent 3e29e0b commit 5f233e3

File tree

9 files changed

+66
-2
lines changed

9 files changed

+66
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

c/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ cbindgen = "0.20.0"
1515
substrait-validator = { path = "../rs", version = "0.0.1" }
1616
libc = "0.2"
1717
thiserror = "1.0"
18+
once_cell = "1.9"

c/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,3 +794,13 @@ pub extern "C" fn substrait_validator_export_proto(
794794
) -> *mut u8 {
795795
export(substrait_validator::export::Format::Proto, handle, size)
796796
}
797+
798+
/// Returns the version of Substrait that the validator was built against.
799+
#[no_mangle]
800+
pub extern "C" fn substrait_validator_substrait_version() -> *const libc::c_char {
801+
static VERSION: once_cell::sync::OnceCell<std::ffi::CString> = once_cell::sync::OnceCell::new();
802+
VERSION
803+
.get_or_init(|| std::ffi::CString::new(substrait_validator::substrait_version()).unwrap())
804+
.as_bytes_with_nul()
805+
.as_ptr() as *const libc::c_char
806+
}

py/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ fn substrait_validator(_py: Python, m: &PyModule) -> PyResult<()> {
251251
Ok(dict.into())
252252
}
253253

254+
/// Returns the version of Substrait that the validator was built against.
255+
#[pyfn(m)]
256+
#[pyo3(name = "get_substrait_version")]
257+
fn get_substrait_version_py(py: Python) -> PyResult<PyObject> {
258+
Ok(substrait_validator::substrait_version().to_object(py))
259+
}
260+
254261
m.add_class::<Config>()?;
255262
m.add_class::<ResultHandle>()?;
256263
Ok(())

py/substrait_validator/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
from typing import Iterable
1111
from google.protobuf import json_format
1212
from google.protobuf.message import DecodeError as ProtoDecodeError
13-
from .substrait_validator import ResultHandle, Config as _Config, get_diagnostic_codes
13+
from .substrait_validator import (
14+
ResultHandle,
15+
Config as _Config,
16+
get_diagnostic_codes,
17+
get_substrait_version as _get_substrait_version,
18+
)
1419
from .substrait.plan_pb2 import Plan
1520
from .substrait.validator.validator_pb2 import ParseResult, Diagnostic, Path
1621

@@ -284,6 +289,12 @@ def path_to_string(path: Path) -> str:
284289
return "".join(elements)
285290

286291

292+
def substrait_version() -> str:
293+
"""Returns the version of Substrait that the validator was built
294+
against."""
295+
return _get_substrait_version()
296+
297+
287298
@click.command()
288299
@click.argument("infile", required=False)
289300
@click.option(

py/tests/test_api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,8 @@ def resolver(s):
154154
},
155155
config,
156156
)
157+
158+
159+
def test_version():
160+
"""Tests whether Substrait version retrieval works."""
161+
assert sv.substrait_version().startswith("v")

rs/build.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,29 @@ fn main() -> Result<()> {
7171
let validator_git_dir = manifest_dir.join("..");
7272
let substrait_git_dir = validator_git_dir.join("substrait");
7373

74+
// Determine Substrait submodule version and write it to a resource
75+
// file.
76+
let substrait_version = std::process::Command::new("git")
77+
.args(["describe", "--tags"])
78+
.current_dir(&substrait_git_dir)
79+
.output()
80+
.expect("failed to get substrait submodule version");
81+
let mut substrait_version = String::from_utf8_lossy(&substrait_version.stdout)
82+
.trim()
83+
.to_string();
84+
let dirty = !std::process::Command::new("git")
85+
.args(["diff", "--quiet"])
86+
.current_dir(&substrait_git_dir)
87+
.status()
88+
.expect("failed to get substrait submodule dirty flag")
89+
.success();
90+
if dirty {
91+
substrait_version += "+dirty";
92+
}
93+
let substrait_version: &str = &substrait_version;
94+
fs::write(resource_dir.join("substrait-version"), substrait_version)
95+
.expect("failed to write substrait submodule version file");
96+
7497
// Synchronize the YAML extension file schema.
7598
synchronize(
7699
&substrait_git_dir,

rs/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,9 @@ pub fn parse<B: prost::bytes::Buf>(buffer: B, config: &Config) -> ParseResult {
5454
pub fn iter_diagnostics() -> impl Iterator<Item = Classification> {
5555
Classification::iter()
5656
}
57+
58+
/// Returns the version of Substrait that this version of the validator was
59+
/// built against.
60+
pub fn substrait_version() -> &'static str {
61+
include_str!("resources/substrait-version")
62+
}

0 commit comments

Comments
 (0)