From 417d9b0e73abadc4836b9d8cc4c4bd01c146d868 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sat, 9 Jan 2016 09:41:12 -0700 Subject: [PATCH] define-runtime-path: add a `#:runtime?-id` option The expression in a `define-runtime-path` form is used in both a run-time context and a compile-time context. The latter is used for `raco exe`. In a cross-build context, you might need to load OpenSSL support for Linux (say) at build time while generating executables that refer to Windows (say) OpenSSL support. In that case, `#:runtime?-id` lets you choose between `(cross-system-type)` and `(system-type)`. Merge to v6.4 --- .../scribblings/reference/filesystem.scrbl | 17 ++++++++++++----- racket/collects/db/private/sqlite3/ffi.rkt | 3 ++- racket/collects/openssl/libcrypto.rkt | 3 ++- racket/collects/openssl/libssl.rkt | 3 ++- racket/collects/racket/runtime-path.rkt | 18 +++++++++++------- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/pkgs/racket-doc/scribblings/reference/filesystem.scrbl b/pkgs/racket-doc/scribblings/reference/filesystem.scrbl index cfc031b488..d5f0f5213a 100644 --- a/pkgs/racket-doc/scribblings/reference/filesystem.scrbl +++ b/pkgs/racket-doc/scribblings/reference/filesystem.scrbl @@ -641,13 +641,18 @@ In addition to the bindings described below, @tech{phase level} 1, since string constants are often used as compile-time expressions with @racket[define-runtime-path]. -@defform[(define-runtime-path id expr)]{ +@defform[(define-runtime-path id maybe-runtime?-id expr) + #:grammar ([maybe-runtime? code:blank + (code:line #:runtime?-id runtime?-id)])]{ Uses @racket[expr] as both a compile-time (i.e., @tech{phase} 1) expression and a run-time (i.e., @tech{phase} 0) expression. In either context, @racket[expr] should produce a path, a string that represents a path, a list of the form @racket[(list 'lib _str ...+)], or a list of the form @racket[(list 'so _str)] or @racket[(list 'so _str _vers)]. +If @racket[runtime?-id] is provided, then it is bound in the context +of @racket[expr] to @racket[#f] for the compile-time instance of +@racket[expr] and @racket[#t] for the run-time instance of @racket[expr]. For run time, @racket[id] is bound to a path that is based on the result of @racket[expr]. The path is normally computed by taking a @@ -781,23 +786,25 @@ Examples: [(windows) '(so "ssleay32")] [else '(so "libssl")])) (define libssl (ffi-lib libssl-so)) -]} +] + +@history[#:changed "6.4" @elem{Added @racket[#:runtime?-id].}]} -@defform[(define-runtime-paths (id ...) expr)]{ +@defform[(define-runtime-paths (id ...) maybe-runtime?-id expr)]{ Like @racket[define-runtime-path], but declares and binds multiple paths at once. The @racket[expr] should produce as many values as @racket[id]s.} -@defform[(define-runtime-path-list id expr)]{ +@defform[(define-runtime-path-list id maybe-runtime?-id expr)]{ Like @racket[define-runtime-path], but @racket[expr] should produce a list of paths.} -@defform[(define-runtime-module-path-index id module-path-expr)]{ +@defform[(define-runtime-module-path-index id maybe-runtime?-id module-path-expr)]{ Similar to @racket[define-runtime-path], but @racket[id] is bound to a @tech{module path index} that encapsulates the result of diff --git a/racket/collects/db/private/sqlite3/ffi.rkt b/racket/collects/db/private/sqlite3/ffi.rkt index d1c4692a0c..d560fd16a2 100644 --- a/racket/collects/db/private/sqlite3/ffi.rkt +++ b/racket/collects/db/private/sqlite3/ffi.rkt @@ -11,7 +11,8 @@ ;; raco distribute should include Racket's sqlite3 if present (define-runtime-path sqlite-so - (case (cross-system-type) + #:runtime?-id runtime? + (case (if runtime? (system-type) (cross-system-type)) [(windows) '(so "sqlite3")] [else '(so "libsqlite3" ("0" #f))])) diff --git a/racket/collects/openssl/libcrypto.rkt b/racket/collects/openssl/libcrypto.rkt index 64e3df7e18..774d9611ca 100644 --- a/racket/collects/openssl/libcrypto.rkt +++ b/racket/collects/openssl/libcrypto.rkt @@ -44,7 +44,8 @@ ;; We need to declare because they might be distributed with Racket, ;; in which case they should get bundled with stand-alone executables: (define-runtime-path libcrypto-so - (case (cross-system-type) + #:runtime?-id runtime? + (case (if runtime? (system-type) (cross-system-type)) [(windows) '(so "libeay32")] [(macosx) ;; Version "1.0.0" is bundled with Racket diff --git a/racket/collects/openssl/libssl.rkt b/racket/collects/openssl/libssl.rkt index f4c4ac1682..66c0f882d6 100644 --- a/racket/collects/openssl/libssl.rkt +++ b/racket/collects/openssl/libssl.rkt @@ -14,7 +14,8 @@ ;; We need to declare because they might be distributed with PLT Scheme ;; in which case they should get bundled with stand-alone executables: (define-runtime-path libssl-so - (case (cross-system-type) + #:runtime?-id runtime? + (case (if runtime? (system-type) (cross-system-type)) [(windows) '(so "ssleay32")] [(macosx) ;; Version "1.0.0" is bundled with Racket diff --git a/racket/collects/racket/runtime-path.rkt b/racket/collects/racket/runtime-path.rkt index 5058e00fdf..98e71c34b5 100644 --- a/racket/collects/racket/runtime-path.rkt +++ b/racket/collects/racket/runtime-path.rkt @@ -161,7 +161,7 @@ (define-syntax (-define-runtime-path stx) (syntax-case stx () - [(_ orig-stx (id ...) expr to-list to-values need-dir?) + [(_ orig-stx (id ...) expr to-list to-values need-dir? runtime?-id) (let ([ids (syntax->list #'(id ...))]) (unless (memq (syntax-local-context) '(module module-begin top-level)) (raise-syntax-error #f "allowed only at the top level" #'orig-stx)) @@ -180,7 +180,7 @@ #'orig-stx))) #`(begin (define-values (id ...) - (let-values ([(id ...) expr]) + (let-values ([(id ...) (let ([runtime?-id #t]) expr)]) (let ([get-dir #,(if (syntax-e #'need-dir?) #`(lambda () (path-of @@ -195,24 +195,28 @@ (begin-for-syntax (register-ext-files (#%variable-reference) - (let-values ([(id ...) expr]) + (let-values ([(id ...) (let ([runtime?-id #f]) expr)]) (to-list id ...))))))])) (define-syntax (define-runtime-path stx) (syntax-case stx () - [(_ id expr) #`(-define-runtime-path #,stx (id) expr list values #t)])) + [(_ id expr) #`(-define-runtime-path #,stx (id) expr list values #t runtime?)] + [(_ id #:runtime?-id runtime?-id expr) #`(-define-runtime-path #,stx (id) expr list values #t runtime?-id)])) (define-syntax (define-runtime-paths stx) (syntax-case stx () - [(_ (id ...) expr) #`(-define-runtime-path #,stx (id ...) expr list values #t)])) + [(_ (id ...) expr) #`(-define-runtime-path #,stx (id ...) expr list values #t runtime?)] + [(_ (id ...) #:runtime?-id runtime?-id expr) #`(-define-runtime-path #,stx (id ...) expr list values #t runtime?-id)])) (define-syntax (define-runtime-path-list stx) (syntax-case stx () - [(_ id expr) #`(-define-runtime-path #,stx (id) expr values list #t)])) + [(_ id expr) #`(-define-runtime-path #,stx (id) expr values list #t runtime?)] + [(_ id #:runtime?-id runtime?-id expr) #`(-define-runtime-path #,stx (id) expr values list #t runtime?-id)])) (define-syntax (define-runtime-module-path-index stx) (syntax-case stx () - [(_ id expr) #`(-define-runtime-path #,stx (id) `(module ,expr ,(#%variable-reference)) list values #f)])) + [(_ id expr) #`(-define-runtime-path #,stx (id) `(module ,expr ,(#%variable-reference)) list values #f runtime?)] + [(_ id #:runtime?-id runtime?-id expr) #`(-define-runtime-path #,stx (id) `(module ,expr ,(#%variable-reference)) list values #f runtime?-id)])) (define-for-syntax required-module-paths (make-hash)) (define-syntax (runtime-require stx)