(zilch lang rust cargo): parse cfg values at runtime
This commit is contained in:
parent
9f23179d46
commit
054b320f27
3 changed files with 34 additions and 37 deletions
10
lang/rust/cfg-fetch.rs
Normal file
10
lang/rust/cfg-fetch.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
use std::{env::var_os, fs::{create_dir, File}, os::unix::process::CommandExt, process::Command};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
Err(
|
||||||
|
Command::new(var_os("rustc").unwrap())
|
||||||
|
.arg("--print=cfg")
|
||||||
|
.stdout(File::create(var_os("out").unwrap()).unwrap())
|
||||||
|
.exec())
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
@ -15,5 +15,6 @@
|
||||||
];
|
];
|
||||||
overrides.preBuild = ''
|
overrides.preBuild = ''
|
||||||
(cat buildrs-runner.rs; printf '\0') | xxd -i -n runner_source > runner_source.h
|
(cat buildrs-runner.rs; printf '\0') | xxd -i -n runner_source > runner_source.h
|
||||||
|
(cat cfg-fetch.rs; printf '\0') | xxd -i -n cfgfetch_source > cfgfetch_source.h
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
(chicken foreign)
|
(chicken foreign)
|
||||||
(srfi 4) (srfi 128) (srfi 146) (srfi 152) (srfi 207)
|
(srfi 4) (srfi 128) (srfi 146) (srfi 152) (srfi 207)
|
||||||
(zilch lang rust registry) (zilch lang rust) (zilch lang rust cfg)
|
(zilch lang rust registry) (zilch lang rust) (zilch lang rust cfg)
|
||||||
|
(zilch lang rust cfg)
|
||||||
(zilch lang go vfs))
|
(zilch lang go vfs))
|
||||||
|
|
||||||
(export
|
(export
|
||||||
|
|
@ -36,6 +37,8 @@
|
||||||
<cargo-workspace> make-cargo-workspace cargo-workspace?
|
<cargo-workspace> make-cargo-workspace cargo-workspace?
|
||||||
cargo-workspace-members cargo-workspace-exclude cargo-workspace-dependencies
|
cargo-workspace-members cargo-workspace-exclude cargo-workspace-dependencies
|
||||||
|
|
||||||
|
cfg-values
|
||||||
|
|
||||||
parse-cargo-toml)
|
parse-cargo-toml)
|
||||||
|
|
||||||
(begin
|
(begin
|
||||||
|
|
@ -182,45 +185,28 @@
|
||||||
(cargo-workspace-exclude entry)
|
(cargo-workspace-exclude entry)
|
||||||
(cargo-workspace-dependencies entry)))
|
(cargo-workspace-dependencies entry)))
|
||||||
|
|
||||||
; TODO(puck): aaaa
|
(foreign-declare "#include \"cfgfetch_source.h\"")
|
||||||
|
(define cfgfetch-bin
|
||||||
|
(cdar
|
||||||
|
(call-rustc
|
||||||
|
(zfile (foreign-value "cfgfetch_source" nonnull-c-string)) '()
|
||||||
|
#:codegen-flags (cons "linker" (force linker))
|
||||||
|
#:crate-type 'bin
|
||||||
|
#:crate-name "cfgfetch"
|
||||||
|
#:edition "2021"
|
||||||
|
#:emits '(#:link #t))))
|
||||||
|
|
||||||
(define cfg-target "x86_64-unknown-linux-gnu")
|
(define cfg-target "x86_64-unknown-linux-gnu")
|
||||||
|
(define (read-cfg-value port rest)
|
||||||
|
(define line (read-line port))
|
||||||
|
(if (eof-object? line)
|
||||||
|
rest
|
||||||
|
(let* ((line (cfg-parse line)))
|
||||||
|
(read-cfg-value port (cons (cdr line) rest)))))
|
||||||
|
|
||||||
(define cfg-values
|
(define cfg-values
|
||||||
'(( "debug_assertions" . #f)
|
(let ((vals (cdar (store-path-for-ca-drv* "cfg-values" "x86_64-linux" #~(#$cfgfetch-bin) #~(("rustc" . ,(string-append #$rustc "/bin/rustc"))) '("out")))))
|
||||||
( "fmt_debug" . "full")
|
(call-with-port (store-path-open vals) (lambda (p) (read-cfg-value p '())))))
|
||||||
( "overflow_checks" . #f)
|
|
||||||
( "panic" . "unwind")
|
|
||||||
( "relocation_model" . "pic")
|
|
||||||
( "target_abi" . "")
|
|
||||||
( "target_arch" . "x86_64")
|
|
||||||
( "target_endian" . "little")
|
|
||||||
( "target_env" . "gnu")
|
|
||||||
( "target_family" . "unix")
|
|
||||||
( "target_feature" . "fxsr")
|
|
||||||
( "target_feature" . "sse")
|
|
||||||
( "target_feature" . "sse2")
|
|
||||||
( "target_has_atomic" . #f)
|
|
||||||
( "target_has_atomic" . "16")
|
|
||||||
( "target_has_atomic" . "32")
|
|
||||||
( "target_has_atomic" . "64")
|
|
||||||
( "target_has_atomic" . "8")
|
|
||||||
( "target_has_atomic" . "ptr")
|
|
||||||
( "target_has_atomic_equal_alignment" . "16")
|
|
||||||
( "target_has_atomic_equal_alignment" . "32")
|
|
||||||
( "target_has_atomic_equal_alignment" . "64")
|
|
||||||
( "target_has_atomic_equal_alignment" . "8")
|
|
||||||
( "target_has_atomic_equal_alignment" . "ptr")
|
|
||||||
( "target_has_atomic_load_store" . #f)
|
|
||||||
( "target_has_atomic_load_store" . "16")
|
|
||||||
( "target_has_atomic_load_store" . "32")
|
|
||||||
( "target_has_atomic_load_store" . "64")
|
|
||||||
( "target_has_atomic_load_store" . "8")
|
|
||||||
( "target_has_atomic_load_store" . "ptr")
|
|
||||||
( "target_os" . "linux")
|
|
||||||
( "target_pointer_width" . "64")
|
|
||||||
( "target_thread_local" . #f)
|
|
||||||
( "target_vendor" . "unknown")
|
|
||||||
( "ub_checks" . #f)
|
|
||||||
( "unix" . #f)))
|
|
||||||
|
|
||||||
(define (cratify-name name)
|
(define (cratify-name name)
|
||||||
; NOTE! string-map _has_ to return a char. non-chars are mistreated and cause memory corruption.
|
; NOTE! string-map _has_ to return a char. non-chars are mistreated and cause memory corruption.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue