Skip to content

Commit b327213

Browse files
Add a test to verify that we have reproducible compiler builds.
1 parent a3dc048 commit b327213

File tree

3 files changed

+180
-0
lines changed

3 files changed

+180
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-include ../tools.mk
2+
all:
3+
$(RUSTC) reproducible-build-aux.rs
4+
$(RUSTC) reproducible-build.rs -o"$(TMPDIR)/reproducible-build1"
5+
$(RUSTC) reproducible-build.rs -o"$(TMPDIR)/reproducible-build2"
6+
cmp "$(TMPDIR)/reproducible-build1" "$(TMPDIR)/reproducible-build2" || exit 1
7+
$(RUSTC) reproducible-build-aux.rs -g
8+
$(RUSTC) reproducible-build.rs -g -o"$(TMPDIR)/reproducible-build1-debug"
9+
$(RUSTC) reproducible-build.rs -g -o"$(TMPDIR)/reproducible-build2-debug"
10+
cmp "$(TMPDIR)/reproducible-build1-debug" "$(TMPDIR)/reproducible-build2-debug" || exit 1
11+
$(RUSTC) reproducible-build-aux.rs -O
12+
$(RUSTC) reproducible-build.rs -O -o"$(TMPDIR)/reproducible-build1-opt"
13+
$(RUSTC) reproducible-build.rs -O -o"$(TMPDIR)/reproducible-build2-opt"
14+
cmp "$(TMPDIR)/reproducible-build1-opt" "$(TMPDIR)/reproducible-build2-opt" || exit 1
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type="lib"]
12+
13+
pub static STATIC: i32 = 1234;
14+
15+
pub struct Struct<T1, T2> {
16+
_t1: std::marker::PhantomData<T1>,
17+
_t2: std::marker::PhantomData<T2>,
18+
}
19+
20+
pub fn regular_fn(_: i32) {}
21+
22+
pub fn generic_fn<T1, T2>() {}
23+
24+
impl<T1, T2> Drop for Struct<T1, T2> {
25+
fn drop(&mut self) {}
26+
}
27+
28+
pub enum Enum {
29+
Variant1,
30+
Variant2(u32),
31+
Variant3 { x: u32 }
32+
}
33+
34+
pub struct TupleStruct(pub i8, pub i16, pub i32, pub i64);
35+
36+
pub trait Trait<T1, T2> {
37+
fn foo(&self);
38+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// This test case makes sure that two identical invocations of the compiler
12+
// (i.e. same code base, same compile-flags, same compiler-versions, etc.)
13+
// produce the same output. In the past, symbol names of monomorphized functions
14+
// were not deterministic (which we want to avoid).
15+
//
16+
// The test tries to exercise as many different paths into symbol name
17+
// generation as possible:
18+
//
19+
// - regular functions
20+
// - generic functions
21+
// - methods
22+
// - statics
23+
// - closures
24+
// - enum variant constructors
25+
// - tuple struct constructors
26+
// - drop glue
27+
// - FnOnce adapters
28+
// - Trait object shims
29+
// - Fn Pointer shims
30+
31+
#![allow(dead_code)]
32+
33+
extern crate reproducible_build_aux;
34+
35+
static STATIC: i32 = 1234;
36+
37+
pub struct Struct<T1, T2> {
38+
x: T1,
39+
y: T2,
40+
}
41+
42+
fn regular_fn(_: i32) {}
43+
44+
fn generic_fn<T1, T2>() {}
45+
46+
impl<T1, T2> Drop for Struct<T1, T2> {
47+
fn drop(&mut self) {}
48+
}
49+
50+
pub enum Enum {
51+
Variant1,
52+
Variant2(u32),
53+
Variant3 { x: u32 }
54+
}
55+
56+
struct TupleStruct(i8, i16, i32, i64);
57+
58+
impl TupleStruct {
59+
pub fn bar(&self) {}
60+
}
61+
62+
trait Trait<T1, T2> {
63+
fn foo(&self);
64+
}
65+
66+
impl Trait<i32, u64> for u64 {
67+
fn foo(&self) {}
68+
}
69+
70+
impl reproducible_build_aux::Trait<char, String> for TupleStruct {
71+
fn foo(&self) {}
72+
}
73+
74+
fn main() {
75+
regular_fn(STATIC);
76+
generic_fn::<u32, char>();
77+
generic_fn::<char, Struct<u32, u64>>();
78+
generic_fn::<Struct<u64, u32>, reproducible_build_aux::Struct<u32, u64>>();
79+
80+
let dropped = Struct {
81+
x: "",
82+
y: 'a',
83+
};
84+
85+
let _ = Enum::Variant1;
86+
let _ = Enum::Variant2(0);
87+
let _ = Enum::Variant3 { x: 0 };
88+
let _ = TupleStruct(1, 2, 3, 4);
89+
90+
let closure = |x| {
91+
x + 1i32
92+
};
93+
94+
fn inner<F: Fn(i32) -> i32>(f: F) -> i32 {
95+
f(STATIC)
96+
}
97+
98+
println!("{}", inner(closure));
99+
100+
let object_shim: &Trait<i32, u64> = &0u64;
101+
object_shim.foo();
102+
103+
fn with_fn_once_adapter<F: FnOnce(i32)>(f: F) {
104+
f(0);
105+
}
106+
107+
with_fn_once_adapter(|_:i32| { });
108+
109+
reproducible_build_aux::regular_fn(STATIC);
110+
reproducible_build_aux::generic_fn::<u32, char>();
111+
reproducible_build_aux::generic_fn::<char, Struct<u32, u64>>();
112+
reproducible_build_aux::generic_fn::<Struct<u64, u32>,
113+
reproducible_build_aux::Struct<u32, u64>>();
114+
115+
let _ = reproducible_build_aux::Enum::Variant1;
116+
let _ = reproducible_build_aux::Enum::Variant2(0);
117+
let _ = reproducible_build_aux::Enum::Variant3 { x: 0 };
118+
let _ = reproducible_build_aux::TupleStruct(1, 2, 3, 4);
119+
120+
let object_shim: &reproducible_build_aux::Trait<char, String> = &TupleStruct(0, 1, 2, 3);
121+
object_shim.foo();
122+
123+
let pointer_shim: &Fn(i32) = &regular_fn;
124+
125+
TupleStruct(1, 2, 3, 4).bar();
126+
}
127+
128+

0 commit comments

Comments
 (0)