How do people deal with platform dependent code on racket?
(Thinking for libraries etc…)
What kind of platform-dependent code?
The simplest answer is (if (eq? 'windows (system-type 'os)) ... ...)
Ah - I’m touching GFX libraries so unfortunately things like vendor code (wayland vs. x, etc…)
Right, but what kind of conditional do you need? Is if
enough, or do you need to compile some files only on some platforms or …?
You might look at racket/gui
for inspiration, because that has a lot of platform-dependent code
Just if
I think would be fine mostly - the question comes from not understanding how racket
distributes code at all (is it source based? Is there some intermediate format?). I’ll take a look at the racet/gui
thanks.
I’m not sure what you mean by “how racket
distributes code”. For example, there are a bunch of binary downloads for on http://download.racket-lang.org\|download.racket-lang.org. Those contain a lot a Racket code. The compiled Racket BC versions use a portable bytecode format for compiled Racket code, which is the same on all platforms. The Racket CS versions use a format that embeds machine code, and is different on different platforms. It’s also possible to create Racket CS compiled files that use a portable format and then are compiled to the non-portable format at installation time.
If you build an application with Racket, then there are of course lots of ways to distribute it. One popular way is using raco exe
and raco distribute
which bundles together your program and the Racket executable; that’s of course platform specific just like the executable is.
Those questions don’t really come into play when you’re talking about what you write in the source code, though.
So when I run raco pkg install
does it essentially download the source and compile to the byte code on my system?
Yes