Skip to content

Commit

Permalink
Merge pull request #2683 from ffortier/master
Browse files Browse the repository at this point in the history
Support hermetic build environment
  • Loading branch information
mthom authored Dec 14, 2024
2 parents a9a7777 + c1571bf commit c59f542
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
31 changes: 7 additions & 24 deletions build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::fs::File;
use std::io::Write;
use std::path::Path;
use std::path::PathBuf;
use std::path::MAIN_SEPARATOR_STR;
use std::process::{Command, Stdio};

fn find_prolog_files(path_prefix: &str, current_dir: &Path) -> Vec<(String, PathBuf)> {
Expand Down Expand Up @@ -61,33 +62,15 @@ fn main() {
let constants = find_prolog_files("", &lib_path);

let out_dir = std::env::var("OUT_DIR").unwrap();
let out_dir_path: &Path = out_dir.as_ref();
let manifest_dir = &std::env::var("CARGO_MANIFEST_DIR").unwrap();
let manifest_dir_path: &Path = manifest_dir.as_ref();

let prefix: PathBuf = if let Ok(diff) = out_dir_path.strip_prefix(manifest_dir_path) {
let mut path = PathBuf::from(".");
for comp in diff.components() {
match comp {
std::path::Component::Normal(_) => path.push(".."),
std::path::Component::CurDir => (),
std::path::Component::Prefix(_)
| std::path::Component::RootDir
| std::path::Component::ParentDir => {
path = manifest_dir_path.to_path_buf();
break;
}
}
}
path
} else {
manifest_dir_path.to_path_buf()
};

writeln!(libraries, "{{").unwrap();
for (name, lib_path) in constants {
let path: PathBuf = prefix.join(lib_path);
writeln!(libraries, "m.insert(\"{name}\", include_str!({path:?}));").unwrap();
let path = format!("{}{}", MAIN_SEPARATOR_STR, lib_path.display());
writeln!(
libraries,
"m.insert(\"{name}\", include_str!(concat!(env!(\"CARGO_MANIFEST_DIR\"), {path:?})));"
)
.unwrap();
}
writeln!(libraries, "}}").unwrap();

Expand Down
2 changes: 1 addition & 1 deletion src/toplevel.pl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:- module('$toplevel', []).
:- module('$toplevel', [repl/0]).

:- use_module(library(charsio)).
:- use_module(library(error)).
Expand Down

0 comments on commit c59f542

Please sign in to comment.