diff --git a/build.rs b/build.rs
index d5bcb5253a4c88453c701ce355fd36fb38cd0e9e..fb1aae9be42e84286565cbe6db1644316b8b8037 100644
--- a/build.rs
+++ b/build.rs
@@ -7,6 +7,7 @@ fn main() {
         rustc_minor_version().expect("Failed to get rustc version");
     let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
     let align_cargo_feature = env::var("CARGO_FEATURE_ALIGN").is_ok();
+    let const_extern_fn_cargo_feature = env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok();
     let libc_ci = env::var("LIBC_CI").is_ok();
 
     if env::var("CARGO_FEATURE_USE_STD").is_ok() {
@@ -72,6 +73,10 @@ fn main() {
     if rustc_dep_of_std {
         println!("cargo:rustc-cfg=libc_thread_local");
     }
+
+    if const_extern_fn_cargo_feature {
+        println!("cargo:rustc-cfg=libc_const_extern_fn");
+    }
 }
 
 fn rustc_minor_version() -> Option<u32> {
diff --git a/tests/const_fn.rs b/tests/const_fn.rs
new file mode 100644
index 0000000000000000000000000000000000000000..4c413c90e8faab511a887c0fcdfe88f42725bc9e
--- /dev/null
+++ b/tests/const_fn.rs
@@ -0,0 +1,5 @@
+#![cfg(libc_const_extern_fn)] // If this does not hold, the file is empty
+
+#[cfg(target_os = "linux")]
+const _FOO: libc::c_uint = unsafe { libc::CMSG_SPACE(1) }; 
+//^ if CMSG_SPACE is not const, this will fail to compile