Skip to content

Commit

Permalink
Merge pull request #133 from Aimeedeer/fix_version_printing
Browse files Browse the repository at this point in the history
hardcoded version number and added test for version checking
  • Loading branch information
brson authored Jan 27, 2023
2 parents ce35823 + e180421 commit ee329e5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 130 deletions.
33 changes: 0 additions & 33 deletions Cargo.lock

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

33 changes: 0 additions & 33 deletions components/conformance-tests/Cargo.lock

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

39 changes: 32 additions & 7 deletions components/conformance-tests/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{Result, Context};
use anyhow::{Context, Result};
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
Expand Down Expand Up @@ -74,7 +74,7 @@ fn run_test(args: TestArgs) -> Result<()> {
assert_eq!(binaryen_out_file, rust_out_file);

let api_out_file = fs::read(api_out.outfile)?;

assert_eq!(api_out_file, rust_out_file);
} else {
assert!(!rust_out.outfile.exists());
Expand Down Expand Up @@ -746,7 +746,7 @@ fn wasm_to_wasm_enable_custom_features() -> Result<()> {
"--enable-gc-nn-locals",
"--enable-relaxed-simd",
"--enable-extended-const",
"--enable-strings",
"--enable-strings",
"--enable-multi-memories",
];

Expand Down Expand Up @@ -784,7 +784,7 @@ fn wasm_to_wasm_disable_custom_features() -> Result<()> {
"--disable-gc-nn-locals",
"--disable-relaxed-simd",
"--disable-extended-const",
"--disable-strings",
"--disable-strings",
"--disable-multi-memories",
];

Expand All @@ -805,8 +805,12 @@ fn wasm_to_wasm_pass_arg() -> Result<()> {
let infile_sourcemap = None::<PathBuf>;
let outfile_sourcemap = None::<PathBuf>;

let args = vec!["--extract-function", "--pass-arg", "extract-function@rust_begin_unwind"];

let args = vec![
"--extract-function",
"--pass-arg",
"extract-function@rust_begin_unwind",
];

run_test(TestArgs {
infile,
infile_sourcemap,
Expand All @@ -825,7 +829,7 @@ fn wasm_to_wasm_converge() -> Result<()> {
let outfile_sourcemap = None::<PathBuf>;

let args = vec!["-Os", "--converge"];

run_test(TestArgs {
infile,
infile_sourcemap,
Expand Down Expand Up @@ -853,3 +857,24 @@ fn input_file_does_not_exist() -> Result<()> {
args,
})
}

#[test]
fn check_versions() -> Result<()> {
let paths = get_paths()?;

let output = Command::new(paths.binaryen_wasm_opt)
.arg("--version")
.output()?;

let version_binaryen = String::from_utf8(output.stdout)?.trim().to_string();

let output = Command::new(paths.rust_wasm_opt)
.arg("--version")
.output()?;

let version_rust = String::from_utf8(output.stdout)?.trim().to_string();

assert_eq!(version_binaryen, version_rust);

Ok(())
}
1 change: 0 additions & 1 deletion components/wasm-opt-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ links = "binaryen"
anyhow = "1.0.58"
cc = { version = "1.0.73", features = ["parallel"] }
cxx-build = "1.0.79"
regex = "1.6.0"

[dependencies]
cxx = "1.0.79"
57 changes: 1 addition & 56 deletions components/wasm-opt-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use cxx_build::CFG;
use regex::Regex;
use std::fmt::Write as FmtWrite;
use std::fs::{self, File};
use std::io::{BufRead, BufReader, BufWriter, Write};
use std::path::{Path, PathBuf};
use std::process::Command;

fn main() -> anyhow::Result<()> {
check_cxx17_support()?;
Expand Down Expand Up @@ -309,66 +307,13 @@ fn create_config_header() -> anyhow::Result<()> {
let output_dir = Path::new(&output_dir);
let config_file = output_dir.join("config.h");

let cmake_version = get_project_version_from_cmake()?;
let mut config_text = format!("#define PROJECT_VERSION \"{}\"", cmake_version);

let git_version = get_project_version_from_git();
match git_version {
Ok(git_version) => {
config_text = format!(
"#define PROJECT_VERSION \"{} ({})\"",
cmake_version, git_version
);
}
Err(_) => {
// Can't get the git version when building from package.
}
}
let config_text = "#define PROJECT_VERSION \"111 (version_111)\"";

fs::write(&config_file, config_text)?;

Ok(())
}

fn get_project_version_from_cmake() -> anyhow::Result<String> {
let re = Regex::new(r".*?binaryen LANGUAGES C CXX VERSION \d+.*?").unwrap();

let binaryen_dir = get_binaryen_dir()?;
let cmake_file = binaryen_dir.join("CMakeLists.txt");

let file = File::open(cmake_file)?;

let version_info: Vec<String> = BufReader::new(file)
.lines()
.map(|line| line.unwrap())
.filter(|line| re.is_match(line.as_ref()))
.collect();

let re = Regex::new(r"\d+").unwrap();
let cap = re.captures(&version_info[0]).expect("cmake version");
let version = &cap[0];

Ok(version.to_string())
}

fn get_project_version_from_git() -> anyhow::Result<String> {
let binaryen_dir = get_binaryen_dir()?;

let output = Command::new("git")
.arg("-C")
.arg(binaryen_dir.as_os_str())
.arg("describe")
.arg("--tags")
.arg("--match")
.arg("version_*")
.output();

let output = output?;
let output = String::from_utf8(output.stdout)?.trim().to_string();

Ok(output)
}

fn check_cxx17_support() -> anyhow::Result<()> {
let mut builder = cc::Build::new();
builder.cpp(true);
Expand Down

0 comments on commit ee329e5

Please sign in to comment.