diff --git a/build.rs b/build.rs
index 66f53f78d31102e020d5b2caffa297d5911f662e..ca727321ee771f17f1ffac92e576d8048abf1359 100644
--- a/build.rs
+++ b/build.rs
@@ -117,6 +117,12 @@ fn main() {
         &env::var("PROFILE").unwrap_or(String::from("UNKNOWN")),
     );
 
+    write_str_constant(
+        &mut file,
+        "OPT_LEVEL",
+        &env::var("OPT_LEVEL").unwrap_or(String::from("UNKNOWN")),
+    );
+
     write_str_constant(
         &mut file,
         "MAKEFLAGS",
diff --git a/src/gen/mock.rs b/src/gen/mock.rs
index b292a5535bfad74d61516726026930cd7cf21e6e..031ffe49be249bfa8d3ac4a512647b675e49d951 100644
--- a/src/gen/mock.rs
+++ b/src/gen/mock.rs
@@ -9,6 +9,7 @@ pub const COMPILER_VERSION: &str = "x.x.x";
 pub const HOST: &str = "-";
 pub const TARGET: &str = "-";
 pub const PROFILE: &str = "-";
+pub const OPT_LEVEL: &str = "-";
 pub const MAKEFLAGS: &str = "-";
 pub const FEATURES: [&str; 1] = ["cpu"];
 pub const PLATFORM_CPU_BITS: &str = "64";