Skip to content

Commit 9e07912

Browse files
committed
drop ipcheck source
1 parent 2139501 commit 9e07912

28 files changed

+986
-0
lines changed

tools/ipcheck/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
artifacts

tools/ipcheck/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# IP Check
2+
3+
Created for https://github.com/rust-lang/rust/pull/76098
4+
5+
This is a little utility program for checking the behavior of various language's IP address implementations.
6+
The goal is to make sure the Rust programs are either the same or deliberately different to other languages.
7+
8+
This same approach might be useful for other APIs that have externally specified behavior that may diverge betweens implementations.
9+
10+
## Implementations
11+
12+
These live under the `impls` directory.
13+
14+
- Rust (New) (`impls/rust`) with the behavior proposed in `#76098`
15+
- Rust (Current) (`impls/rust_current`) with the current behavior on `nightly`
16+
- .NET (`impls/dotnet`)
17+
- Python (`impls/python`)
18+
- Go (`impls/go`)
19+
- Java (`impls/java`)
20+
21+
## Running
22+
23+
With the comparison languages available, you can run `cd host && cargo run` to compare them.
24+
The results are written as a Markdown table to `stdout`.
25+
The set of interesting inputs to compare comes from the `/host/input.txt` file.
26+
27+
## How it works
28+
29+
The _host_ program (under `/host`) will attempt to build and execute a number of language implementations.
30+
Each language implementation will accept an input via `stdin` and write a JSON payload to `stdout` containing the results of its execution.
31+
These payloads are then compared against a reference implementation to see how they're affected by different inputs.

tools/ipcheck/host/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
Cargo.lock

tools/ipcheck/host/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "ipcheck-host"
3+
version = "0.0.0"
4+
authors = ["Ashley Mannix <[email protected]>", "Christiaan Dirkx <[email protected]>"]
5+
publish = false
6+
edition = "2018"
7+
build = "build/build.rs"
8+
9+
[[bin]]
10+
name = "ipcheck-host"
11+
path = "main.rs"
12+
13+
[dependencies]
14+
serde_json = "1"
15+
16+
[build-dependencies]
17+
cfg-if = "1"
18+
walkdir = "2"

tools/ipcheck/host/build/build.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
mod dotnet;
2+
mod go;
3+
mod java;
4+
mod python;
5+
mod rust;
6+
7+
fn main() {
8+
if !std::path::Path::new("../artifacts").exists() {
9+
std::fs::create_dir("../artifacts").expect("failed to create artifacts dir");
10+
}
11+
12+
let mut impls =
13+
std::fs::File::create("../artifacts/.impls").expect("failed to create .impls file");
14+
15+
output_impl(&mut impls, "Rust (New)", rust::build_new());
16+
output_impl(&mut impls, "Rust (Current)", rust::build_current());
17+
output_impl(&mut impls, ".NET", dotnet::build());
18+
output_impl(&mut impls, "Python", python::build());
19+
output_impl(&mut impls, "Go", go::build());
20+
output_impl(&mut impls, "Java", java::build());
21+
22+
rerun_if_changed("build");
23+
rerun_if_changed("../impls");
24+
}
25+
26+
fn output_impl(
27+
file: &mut std::fs::File,
28+
lang: impl AsRef<str>,
29+
result: std::io::Result<impl AsRef<str>>,
30+
) {
31+
use std::io::Write;
32+
33+
let lang = lang.as_ref();
34+
35+
println!("Building {}", lang);
36+
37+
match result {
38+
Ok(artifact) => {
39+
writeln!(file, "{}: {}", lang, artifact.as_ref()).expect("failed to write .impls file")
40+
}
41+
Err(err) => {
42+
println!("cargo:warning=Failed to build {} impl: {}", lang, err)
43+
}
44+
}
45+
}
46+
47+
fn rerun_if_changed(dir: &str) {
48+
for entry in walkdir::WalkDir::new(dir) {
49+
if let Ok(entry) = entry {
50+
println!("cargo:rerun-if-changed={}", entry.path().display());
51+
}
52+
}
53+
}

tools/ipcheck/host/build/dotnet.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
pub fn build() -> std::io::Result<&'static str> {
2+
if !std::path::Path::new("../artifacts/dotnet").exists() {
3+
std::fs::create_dir("../artifacts/dotnet").expect("failed to create .NET artifacts dir");
4+
}
5+
6+
std::fs::copy(
7+
"../impls/dotnet/IPCheck.cs",
8+
"../artifacts/dotnet/IPCheck.cs",
9+
)?;
10+
std::fs::copy(
11+
"../impls/dotnet/IPCheck.csproj",
12+
"../artifacts/dotnet/IPCheck.csproj",
13+
)?;
14+
15+
let output = std::process::Command::new("dotnet").args(&["--version"]).output()?;
16+
17+
if output.status.success() {
18+
Ok("dotnet run -p ../artifacts/dotnet/IpCheck.csproj")
19+
} else {
20+
Err(std::io::Error::new(
21+
std::io::ErrorKind::Other,
22+
format!("{:?}", String::from_utf8_lossy(&output.stderr)),
23+
))
24+
}
25+
}

tools/ipcheck/host/build/go.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pub fn build() -> std::io::Result<&'static str> {
2+
if !std::path::Path::new("../artifacts/go").exists() {
3+
std::fs::create_dir("../artifacts/go").expect("failed to create Go artifacts dir");
4+
}
5+
6+
let output = std::process::Command::new("go")
7+
.args(&["build", "-o", "../../artifacts/go", "ipcheck.go"])
8+
.current_dir("../impls/go")
9+
.output()?;
10+
11+
if output.status.success() {
12+
Ok("../artifacts/go/ipcheck")
13+
} else {
14+
Err(std::io::Error::new(
15+
std::io::ErrorKind::Other,
16+
format!("{:?}", String::from_utf8_lossy(&output.stderr)),
17+
))
18+
}
19+
}

tools/ipcheck/host/build/java.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
pub fn build() -> std::io::Result<&'static str> {
2+
if !std::path::Path::new("../artifacts/java").exists() {
3+
std::fs::create_dir("../artifacts/java").expect("failed to create Java artifacts dir");
4+
}
5+
6+
std::fs::copy(
7+
"../impls/java/IpCheck.java",
8+
"../artifacts/java/IpCheck.java",
9+
)?;
10+
11+
let output = std::process::Command::new("java").args(&["--version"]).output()?;
12+
13+
if output.status.success() {
14+
Ok("java ../artifacts/java/IpCheck.java")
15+
} else {
16+
Err(std::io::Error::new(
17+
std::io::ErrorKind::Other,
18+
format!("{:?}", String::from_utf8_lossy(&output.stderr)),
19+
))
20+
}
21+
}

tools/ipcheck/host/build/python.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
pub fn build() -> std::io::Result<&'static str> {
2+
if !std::path::Path::new("../artifacts/python").exists() {
3+
std::fs::create_dir("../artifacts/python").expect("failed to create Python artifacts dir");
4+
}
5+
6+
std::fs::copy(
7+
"../impls/python/ipcheck.py",
8+
"../artifacts/python/ipcheck.py",
9+
)?;
10+
11+
let output = std::process::Command::new("python").args(&["--version"]).output()?;
12+
13+
if output.status.success() {
14+
Ok("python ../artifacts/python/ipcheck.py")
15+
} else {
16+
Err(std::io::Error::new(
17+
std::io::ErrorKind::Other,
18+
format!("{:?}", String::from_utf8_lossy(&output.stderr)),
19+
))
20+
}
21+
}

tools/ipcheck/host/build/rust.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use std::path::Path;
2+
3+
pub fn build_new() -> std::io::Result<String> {
4+
build_bin("../impls/rust_new", "../artifacts/rust_new", "ipcheck_new")
5+
}
6+
7+
pub fn build_current() -> std::io::Result<String> {
8+
build_bin(
9+
"../impls/rust_current",
10+
"../artifacts/rust_current",
11+
"ipcheck_current",
12+
)
13+
}
14+
15+
fn build_bin(
16+
src_path: impl AsRef<Path>,
17+
artifact_path: impl AsRef<Path>,
18+
bin: &str,
19+
) -> std::io::Result<String> {
20+
let src_path = src_path.as_ref();
21+
let artifact_path = artifact_path.as_ref();
22+
23+
if !std::path::Path::new(artifact_path).exists() {
24+
std::fs::create_dir(artifact_path).expect("failed to create Rust artifacts dir");
25+
}
26+
27+
std::fs::copy(src_path.join("main.rs"), artifact_path.join("main.rs"))?;
28+
std::fs::copy(
29+
src_path.join("Cargo.toml"),
30+
artifact_path.join("Cargo.toml"),
31+
)?;
32+
33+
let output = std::process::Command::new("cargo")
34+
.args(&[
35+
"+nightly",
36+
"build",
37+
"--release",
38+
"-Z",
39+
"unstable-options",
40+
"--out-dir",
41+
".",
42+
])
43+
.current_dir(artifact_path)
44+
.output()?;
45+
46+
if output.status.success() {
47+
Ok(artifact_path.join(bin).to_string_lossy().into_owned())
48+
} else {
49+
Err(std::io::Error::new(
50+
std::io::ErrorKind::Other,
51+
format!("{:?}", String::from_utf8_lossy(&output.stderr)),
52+
))
53+
}
54+
}

0 commit comments

Comments
 (0)