zilch/lang/rust/src/build-script.sld

44 lines
1.6 KiB
Text
Raw Normal View History

;; Helper procedure to call a build script with the right working directory.
2024-11-25 22:06:44 +00:00
(define-library (zilch lang rust build-script)
(import
(scheme base) (scheme write) (scheme process-context) (scheme lazy)
(zilch file) (zilch magic) (zilch nix drv) (zilch nix path) (scheme char)
(zilch nixpkgs) (zilch zexpr) (zilch semver)
json
(chicken process)
(chicken base) (chicken format)
(chicken foreign)
(srfi 4) (srfi 128) (srfi 146) (srfi 152) (srfi 207)
(zilch lang rust))
(export
call-runner)
(begin
(define linker (delay (let ((v (cdr (assoc "out" (nixpkgs "gcc"))))) #~,(string-append #$v "/bin/cc"))))
(foreign-declare "#include \"runner_source.h\"")
(define runner-runner
(cdar
(call-rustc
(zfile (foreign-value "runner_source" nonnull-c-string)) '()
#:codegen-flags (cons "linker" (force linker))
#:crate-type 'bin
#:crate-name "runner"
#:edition "2021"
#:emits '(#:link #t))))
;; Call a build script with specified current working directory (as string)
;; and environment (as alist).
2024-11-25 22:06:44 +00:00
(define (call-runner input-script cwd env)
2025-02-12 13:12:04 +00:00
(define output (store-path-for-ca-drv* "build.rs-run" "x86_64-linux"
`(,runner-runner)
#~(("script" . #$input-script)
("cwd" . #$cwd)
("OUT_DIR" . ,(make-placeholder "outdir"))
("CARGO_TARGET_DIR" . ,(make-placeholder "targetdir"))
2025-02-12 13:12:04 +00:00
. #$env)
'("out" "outdir" "targetdir")))
2025-02-12 13:12:04 +00:00
(values (cdr (assoc "outdir" output)) (cdr (assoc "out" output))))))
2024-11-25 22:06:44 +00:00