Skip to content

Commit

Permalink
read versions from built.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
pront committed Aug 29, 2023
1 parent b125221 commit 115ce86
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 45 deletions.
22 changes: 0 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/vector-vrl/web-playground/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ gloo-utils = { version = "0.2", features = ["serde"] }
getrandom = { version = "0.2", features = ["js"] }
vector-vrl-functions = { path = "../functions" }
enrichment = { path = "../../enrichment" }
built = { version = "0.6.1" }

[build-dependencies]
cargo_toml = "0.15.3"
19 changes: 9 additions & 10 deletions lib/vector-vrl/web-playground/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ fn write_build_constants(manifest: &Manifest, dest_path: &Path) -> io::Result<()
"// AUTOGENERATED CONSTANTS. SEE BUILD.RS AT REPOSITORY ROOT. DO NOT MODIFY.\n".as_ref(),
)?;

let vector_version_const = format!(
"pub const {}: &str = \"{}\"",
"VECTOR_VERSION",
manifest.package().version()
);
let create_const_statement =
|name, value| format!("pub const {}: &str = \"{}\";\n", name, value);
// TODO: For releases, we should use the manifest.package().version().
let vector_version_const = create_const_statement("VECTOR_VERSION", "master");
output_file
.write_all(vector_version_const.as_bytes())
.expect("Failed to write Vector version constant");
Expand All @@ -40,18 +39,18 @@ fn write_build_constants(manifest: &Manifest, dest_path: &Path) -> io::Result<()
.detail()
.unwrap()
.version
.clone()
.unwrap();
let vrl_version_const = format!("pub const {}: &str = \"{}\"", "VRL_VERSION", vrl_version);
let vrl_version_const = create_const_statement("VRL_VERSION", vrl_version);
output_file
.write_all(vector_version_const.as_bytes())
.write_all(vrl_version_const.as_bytes())
.expect("Failed to write Vector version constant");
Ok(())
}

fn main() {
//println!("cargo:rerun-if-changed(../../../Cargo.toml");
let manifest =
Manifest::from_path(&get_vector_toml_path()).expect("Failed to load Vector Cargo.toml");
let dst = std::path::Path::new(&env::var("OUT_DIR").unwrap()).join("built.rs");
Manifest::from_path(get_vector_toml_path()).expect("Failed to load Vector Cargo.toml");
let dst = Path::new(&env::var("OUT_DIR").unwrap()).join("built.rs");
write_build_constants(&manifest, &dst).expect("Failed to write constants");
}
6 changes: 2 additions & 4 deletions lib/vector-vrl/web-playground/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
<div id="App">
<div id="summary-section">
<h1>VRL Playground</h1>
<p id="version-paragraph"></p>
<script>
document.getElementById("version-paragraph").innerText = "VRL Version: " + vrlPlayground.version();
</script>
<p id="vector-version"></p>
<p id="vrl-version"></p>
<p>
<a href="https://vector.dev/docs/reference/vrl/functions/">Vector Remap Language (VRL)</a> is an expression-oriented language designed for transforming
observability data. This playground lets you write a program, run it against an event or
Expand Down
8 changes: 7 additions & 1 deletion lib/vector-vrl/web-playground/public/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import init, { run_vrl } from "./pkg/vector_vrl_web_playground.js";
import init, { run_vrl, vrl_version, vector_version } from "./pkg/vector_vrl_web_playground.js";
import { vrlLanguageDefinition, vrlThemeDefinition } from "./vrl-highlighter.js";

const PROGRAM_EDITOR_DEFAULT_VALUE = `# Remove some fields
Expand Down Expand Up @@ -38,6 +38,12 @@ export class VrlWebPlayground {
constructor() {
let temp = init().then(() => {
this.run_vrl = run_vrl;

window.onload = function() {
document.getElementById("vector-version").innerText = "Vector Version: " + vector_version();
document.getElementById("vrl-version").innerText = "VRL Version: " + vrl_version();
};

// require is provided by loader.min.js.
require.config({
paths: { vs: "https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.26.1/min/vs" },
Expand Down
6 changes: 4 additions & 2 deletions lib/vector-vrl/web-playground/public/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
],
"module": "vector_vrl_web_playground.js",
"types": "vector_vrl_web_playground.d.ts",
"sideEffects": false
}
"sideEffects": [
"./snippets/*"
]
}
10 changes: 5 additions & 5 deletions lib/vector-vrl/web-playground/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use vrl::value::Secrets;
use vrl::value::Value;
use wasm_bindgen::prelude::*;

// pub mod vector_built_info {
// include!(concat!(env!("OUT_DIR"), "/vector_built.rs"));
// }
pub mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}

#[derive(Serialize, Deserialize)]
pub struct Input {
Expand Down Expand Up @@ -117,10 +117,10 @@ pub fn run_vrl(incoming: &JsValue) -> JsValue {

#[wasm_bindgen]
pub fn vector_version() -> String {
"".to_string()
built_info::VECTOR_VERSION.to_string()
}

#[wasm_bindgen]
pub fn vrl_version() -> String {
"".to_string()
built_info::VRL_VERSION.to_string()
}

0 comments on commit 115ce86

Please sign in to comment.