Skip to content

Commit 17269e7

Browse files
committed
Check nasm availability and give good error message when not.
1 parent 6382a20 commit 17269e7

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

langs/a86/check-nasm.rkt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#lang racket
2+
(provide check-nasm-available)
3+
(require racket/gui/dynamic)
4+
5+
(define nasm-msg
6+
#<<HERE
7+
nasm not found: either you have not installed nasm
8+
or it cannot be found in your PATH: ~a.~a
9+
HERE
10+
)
11+
12+
(define macosx-msg
13+
#<<HERE
14+
15+
16+
It appears you launched DrRacket using Finder, which
17+
does properly set up the PATH environment variable.
18+
Try launching DrRacket from the command line using the
19+
'drracket' command.
20+
HERE
21+
)
22+
23+
(define (macos?)
24+
(eq? 'macosx (system-type 'os)))
25+
26+
;; This will lie if you happen to run drracket from /, but that's OK.
27+
(define (launched-with-finder?)
28+
(equal? (string->path "/") (find-system-path 'orig-dir)))
29+
30+
(define (drracket?)
31+
(gui-available?))
32+
33+
(define (check-nasm-available)
34+
(unless (parameterize ([current-output-port (open-output-string)]
35+
[current-error-port (open-output-string)])
36+
(system "nasm -v"))
37+
(error (format nasm-msg
38+
(getenv "PATH")
39+
(if (and (drracket?) (macos?) (launched-with-finder?)) macosx-msg "")))))

langs/a86/interp.rkt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
[asm-interp (-> (listof instruction?) any/c)]
55
[asm-interp/io (-> (listof instruction?) string? any/c)])
66

7-
(require "printer.rkt" "ast.rkt" "callback.rkt"
7+
(require "printer.rkt" "ast.rkt" "callback.rkt" "check-nasm.rkt"
88
(rename-in ffi/unsafe [-> _->]))
99
(require (submod "printer.rkt" private))
1010

11+
;; Check NASM availability when required to fail fast.
12+
(check-nasm-available)
13+
1114
;; Assembly code is linked with object files in this parameter
1215
(define current-objs
1316
(make-parameter '()))

0 commit comments

Comments
 (0)