|
| 1 | +# System.jl |
| 2 | + |
| 3 | +[](https://github.com/analytech-solutions/System.jl/actions) |
| 4 | + |
| 5 | +A framework for interfacing with system-installed software from Julia. |
| 6 | + |
| 7 | +System.jl allows for the use of trusted system software without relying on the binaries downloaded as Julia artifacts. |
| 8 | +We view System.jl as an essential component for proprietary and secure computing environments. |
| 9 | +This package does not yet support all platforms (only common Linux distributions at present), but it provides a path to that goal. |
| 10 | +It also requires that the header files are installed for libraries so that bindings can be automatically generated from them. |
| 11 | + |
| 12 | + |
| 13 | +# Usage |
| 14 | + |
| 15 | +System.jl is a framework providing bindings to operating system and system-installed software API's. |
| 16 | +System resources are available as Julia packages that encapsulate dynamically generated bindings (automatically created by [CBinding.jl](https://github.com/analytech-solutions/CBinding.jl) when you import the package). |
| 17 | +These packages can be found in the `System.jl/pkgs` directory and are only available for use once System.jl has been imported. |
| 18 | +Therefore, [similar to Revise.jl](https://timholy.github.io/Revise.jl/stable/config), `using System` must occur before any packages utilizing the framework are loaded, or just add it to your `~/.julia/config/startup.jl` file. |
| 19 | + |
| 20 | +Bindings for a system resource are loaded with the `@sys using libxyz` macro syntax. |
| 21 | +The bindings can always be referenced with the CBinding.jl `c"..."` string macro, but usually the bindings are free of name collisions so Julian names are available as well. |
| 22 | + |
| 23 | +```jl |
| 24 | +julia> using System |
| 25 | + |
| 26 | +julia> @sys using libc.C99 |
| 27 | + |
| 28 | +julia> c"printf"("printf is the best!\n") |
| 29 | +printf is the best! |
| 30 | +20 |
| 31 | + |
| 32 | +julia> @sys using alsa.libasound |
| 33 | + |
| 34 | +julia> for val in 0:Int(SND_PCM_STREAM_LAST) |
| 35 | + name = snd_pcm_stream_name(val) |
| 36 | + c"printf"("%s\n", name) |
| 37 | + end |
| 38 | +PLAYBACK |
| 39 | +CAPTURE |
| 40 | +``` |
| 41 | + |
| 42 | + |
| 43 | +# Developing a framework package |
| 44 | + |
| 45 | +Packages within the System.jl framework, found in `System.jl/pkgs`, are not known about by Pkg.jl when packages are installed. |
| 46 | +Therefore, the framework packages are unable to use _any_ packages that are not referenced by the System.jl package itself (its dependencies are all Pkg.jl knows about). |
| 47 | +Framework packages are generally light-weight uses of CBinding.jl, but the special `sys` package introduces tools to facilitate the process. |
| 48 | + |
| 49 | +It provides the `@pkgconf` macro to automatically inject the dependency packages' compilation command line arguments and header file inclusions in order to prepare both the Julia and C definitions needed to declare the package's bindings. |
| 50 | +The following example demonstrates the usage of this macro: |
| 51 | + |
| 52 | +```jl |
| 53 | +module libpkg |
| 54 | + using sys |
| 55 | + |
| 56 | + @pkgconf begin |
| 57 | + using libdep1, libdep2 |
| 58 | + c`-I/path/to/include -L/path/to/libs -lpkg` |
| 59 | + c""" |
| 60 | + #include <pkg/header-1.h> |
| 61 | + #include <pkg/header-2.h> |
| 62 | + """ji |
| 63 | + end |
| 64 | +end |
| 65 | +``` |
| 66 | + |
| 67 | +And what the manually written equivalent might look like: |
| 68 | + |
| 69 | +```jl |
| 70 | +module libpkg |
| 71 | + using sys |
| 72 | + |
| 73 | + using libdep1 |
| 74 | + using libdep2 |
| 75 | + |
| 76 | + c`-L/dep1/lib -ldep1 -DDEP2_USE_DEP1=1 -L/dep2/lib -ldep2 -I/path/to/include -L/path/to/lib -lpkg` |
| 77 | + |
| 78 | + c""" |
| 79 | + #include <dep1/header-1.h> |
| 80 | + #include <dep1/header-2.h> |
| 81 | + """s |
| 82 | + |
| 83 | + c""" |
| 84 | + #include <dep2/header-1.h> |
| 85 | + #include <dep2/header-2.h> |
| 86 | + """s |
| 87 | + |
| 88 | + c""" |
| 89 | + #include <pkg/header-1.h> |
| 90 | + #include <pkg/header-2.h> |
| 91 | + """ji |
| 92 | +end |
| 93 | +``` |
| 94 | + |
| 95 | +Further details will become available as the package grows and is tested on more systems. |
| 96 | + |
0 commit comments