Julia Binary Artifacts for Dummies

Understanding how Julia Packages are able to only pick binaries for your particular architecture.

SDL Example

(@v1.5) pkg> add SimpleDirectMediaLayer
name = "SimpleDirectMediaLayer"
uuid = "98e33af6-2ee5-5afd-9e75-cbc738b767c4"
repo = "https://github.com/jonathanBieler/SimpleDirectMediaLayer.jl.git"
version = "0.2.1"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
SDL2_image_jll = "41f3cfe1-fd11-58ad-8074-b9730c29438b"
SDL2_jll = "ab825dc5-c88e-5901-9575-1e5e20358fcf"
SDL2_mixer_jll = "7e88e5ca-120e-58e7-9660-b2187fd466c0"
SDL2_ttf_jll = "ca9d4746-8a27-5104-babe-80f83b336947"
[[SDL2]]
arch = "aarch64"
git-tree-sha1 = "34bab89e489684e2be54265098661e07cef18caf"
libc = "glibc"
os = "linux"

[[SDL2.download]]
sha256 = "2ff482d1ff6ec7643b7bdc14a7fe821bfcb0959005fc328b21c11569d09fc36a"
url = "https://github.com/JuliaBinaryWrappers/SDL2_jll.jl/releases/download/SDL2-v2.0.12+1/SDL2.v2.0.12.aarch64-linux-gnu.tar.gz"
[[SDL2]]
arch = "aarch64"
git-tree-sha1 = "2029f4ace28f81e0f34fc6018ebe7e226abbdda9"
libc = "musl"
os = "linux"

[[SDL2.download]]
sha256 = "b78715ef97afdb4317693d672f72f17c5c88a26f644db512221efdd5389ccefc"
url = "https://github.com/JuliaBinaryWrappers/SDL2_jll.jl/releases/download/SDL2-v2.0.12+1/SDL2.v2.0.12.aarch64-linux-musl.tar.gz"

A TOML Crash Course

xs   = [ 1, 2, 3 ]
strs = [ "Commas", "are", "delimiters" ]
[table-1]
key1 = "some string"
key2 = 123
[[foobar]]
arch = "x86_64"
git-tree-sha1 = "5fc005bfb4a5436fcde1cc097be47a3f323b8a14"
os = "macos"

[[foobar]]
arch = "x86_64"
git-tree-sha1 = "9a8dfae78dac5de25e62705aa4017b399e267160"
libc = "glibc"
os = "linux"

[[foobar]]
arch = "x86_64"
git-tree-sha1 = "70d6addecf4f1e67ac4470ee9839bcb07e19d773"
os = "windows"
julia> artifact"foobar"
"~/.julia/artifacts/5fc005bfb4a5436fcde1cc097be47a3f323b8a14"
julia> artifact"foobar"
ERROR: Cannot locate artifact 'foobar' in '~/Development/Julia/ArtifactsPlay/Artifacts.toml'

Creating a Artifacts.toml for Different Binaries

ArtifactsPlay
├── README.md
├── Artifacts.toml
├── create-artifacts.jl
├── src
│ └── ArtifactsPlay.jl
├── lindata
│ ├── msg.txt
│ └── os.txt
├── macdata
│ ├── msg.txt
│ └── os.txt
└── windata
├── msg.txt
└── os.txt
$ cat lindata/msg.txt
Hello Linux user!

$ cat macdata/msg.txt
Hello macOS user!

$ cat windata/os.txt
Windows
using Pkg.Artifacts
using Pkg.BinaryPlatforms

hash = artifact_hash("foobar", "Artifacts.toml")

if !isnothing(hash) && artifact_exists(hash)
return
end
mac_hash = create_artifact() do dir
cp("macdata/msg.txt", joinpath(dir, "msg.txt"))
cp("macdata/os.txt", joinpath(dir, "os.txt"))
end

Making Tarballs

mac_tar_hash = archive_artifact(mac_hash, "foobar-mac.tar.gz")

Record Artifact in Artifacts.toml

mac_path = joinpath(pwd(), "foobar-mac.tar.gz")

bind_artifact!("Artifacts.toml", "foobar", mac_hash,
platform=MacOS(:x86_64),
download_info=[("file:" * mac_path, mac_tar_hash)])
arch = "x86_64"
os = "macos"
lin_tar_hash = archive_artifact(lin_hash, "foobar-lin.tar.gz")
lin_path = joinpath(pwd(), "foobar-lin.tar.gz")

bind_artifact!("Artifacts.toml", "foobar", lin_hash,
platform=Linux(:x86_64),
download_info=[("file:" * lin_path, lin_tar_hash)])
[[foobar]]
arch = "x86_64"
git-tree-sha1 = "5fc005bfb4a5436fcde1cc097be47a3f323b8a14"
os = "macos"

[[foobar.download]]
sha256 = "6fedc42acebe6c82825b8a4a53008d899affe45db582f89028876134d70ba61f"
url = "file:/home/steve/ArtifactsPlay/foobar-mac.tar.gz"

[[foobar]]
arch = "x86_64"
git-tree-sha1 = "9a8dfae78dac5de25e62705aa4017b399e267160"
libc = "glibc"
os = "linux"

[[foobar.download]]
sha256 = "107e0faba3ba11b7adc7e2cc648cfe1ab0d19e4eacf7698d1f1f1d446f921561"
url = "file:/home/steve/ArtifactsPlay/foobar-lin.tar.gz"

[[foobar]]
arch = "x86_64"
git-tree-sha1 = "70d6addecf4f1e67ac4470ee9839bcb07e19d773"
os = "windows"

[[foobar.download]]
sha256 = "3faa9e386c1b0407b669d9ad7a553eeb70d91ee1bb8f56cf2a97281d15a851b4"
url = "file:/home/steve/ArtifactsPlay/foobar-win.tar.gz"

Accessing Artifacts

julia> mac_hash = "5fc005bfb4a5436fcde1cc097be47a3f323b8a14";

julia> lin_hash = "9a8dfae78dac5de25e62705aa4017b399e267160";

julia> win_hash = "70d6addecf4f1e67ac4470ee9839bcb07e19d773";
julia> using Pkg.Artifacts

julia> rm(artifact_path(Base.SHA1(mac_hash)), recursive=true)
julia> rm(artifact_path(Base.SHA1(lin_hash)), recursive=true)
julia> rm(artifact_path(Base.SHA1(win_hash)), recursive=true)
function greet()
path = joinpath(artifact"foobar", "msg.txt")
println(read(path, String))
end
julia> greet()
Downloading artifact: foobar
##O=# #
Downloading artifact: foobar
Hello macOS user!

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store