packageracketraco

Package dependencies based on platform (or operating system) in Racket


I have a package that uses platform dependent system libraries, each of which are separated out into there own package. Is there a way I could install a different dependency based on what platform I am installing on?

The most naive solution would be to have the package depend on all of them:

#lang info
...
(define deps '("mypackage-windows" "mypackage-osx"))

But then mypackage-windows and mypackage-osx get installed even if they're not needed. Worse still, I then need to ensure that the OS X and Windows specific packages don't cause issues when installed on the wrong platform.

So, there any way I can tell raco to only install the packages that I need based on each platform?


Solution

  • Yes there is. You can use the #:platform symbol in the deps portion of your info.rkt file to do this.

    You can find documentation on it here, and an example of it in the racket-gui package.

    You can use 'osx 'unix and 'windows to determine what platform you are on.

    So your example would look like:

    #lang info
    ...
    (define deps '((mypackage-windows #:platform windows)
                   (mypackage-osx     #:platform osx))
    

    In fact, if you wanted to have a different version of your package that work differently on 36 and 64 (and even ppc) variants of each you can do that too:

    #lang info
    ...
    (define deps '((mypackage-windows-64 #:platform "win32\\x86_64")
                   (mypackage-windows-32 #:platform "wind32\\i386")
                   (mypackage-osx-64     #:platform "x86_64-macosx")
                   (mypackage-osx-32     #:platform "i386-macosx")
                   (mypackage-osx-ppc    #:platform "ppc-macosx")))