build.rs

branch
dev
changeset 61
4f468d35fa29
parent 6
bcb508479948
--- a/build.rs	Sun Apr 27 15:03:51 2025 -0500
+++ b/build.rs	Thu Feb 26 11:38:43 2026 -0500
@@ -1,20 +1,39 @@
+use regex::{Captures, Regex};
 use std::env;
-use regex::{Regex, Captures};
 
-fn proc<A : AsRef<str>>(re : &str, str : A) -> String {
-    let need_to_escape = Regex::new(r"([_*\\])").unwrap();
-    Regex::new(re).unwrap().replace_all(str.as_ref(), |caps : &Captures| {
-        format!("{}{}{}",
-            caps.get(1).unwrap().as_str(),
-            need_to_escape.replace_all(caps.get(2).unwrap().as_str(), "\\$1"),
-            caps.get(3).unwrap().as_str()
-        )
-    }).to_string()
+fn main() {
+    process_readme();
+    // Does not seem to be needed now.
+    //discover_gsl();
 }
 
-fn main() {
+/*
+/// Discover how to link to gsl, as the gsl crate does not provide this information
+fn discover_gsl() {
+    pkg_config::Config::new().probe("gsl").unwrap();
+}
+*/
+
+/// `\`-escape `_`, `*`, and ยด\\` in matches of `re` within `str`.
+fn proc<A: AsRef<str>>(re: &str, str: A) -> String {
+    let need_to_escape = Regex::new(r"([_*\\])").unwrap();
+    Regex::new(re)
+        .unwrap()
+        .replace_all(str.as_ref(), |caps: &Captures| {
+            format!(
+                "{}{}{}",
+                caps.get(1).unwrap().as_str(),
+                need_to_escape.replace_all(caps.get(2).unwrap().as_str(), "\\$1"),
+                caps.get(3).unwrap().as_str()
+            )
+        })
+        .to_string()
+}
+
+/// Process the README for inclusion in documentation
+fn process_readme() {
     let out_dir = env::var("OUT_DIR").unwrap();
-    
+
     // Since rust is stuck in 80's 7-bit gringo ASCII world, so that rustdoc does not support
     // markdown KaTeX mathematics, we have to process the README to include horrible horrible
     // horrible escapes for the math, and then use an vomit-inducingly ugly javasccript
@@ -22,12 +41,13 @@
 
     println!("cargo:rerun-if-changed=README.md");
 
-    let readme = std::fs::read_to_string("README.md")
-        .expect("Error reading README");
+    let readme = std::fs::read_to_string("README.md").expect("Error reading README");
 
     // Escape _, *, and \ in equations.
-    let readme_uglified = proc(r"(?m)([^$]\$)([^$]+)(\$[^$])",
-                               proc(r"([^$]\$\$)([^$]+)(\$\$[^$])", readme));
+    let readme_uglified = proc(
+        r"(?m)([^$]\$)([^$]+)(\$[^$])",
+        proc(r"([^$]\$\$)([^$]+)(\$\$[^$])", readme),
+    );
     // Remove the instructions for building the documentation
     let readme_cut = Regex::new("## Internals(.*|\n)*")
         .unwrap()

mercurial