Skip to content

Commit

Permalink
move build code into create_binaries package (#762)
Browse files Browse the repository at this point in the history
Follow up to #740.

---------

Co-authored-by: Hofer-Julian <[email protected]>
  • Loading branch information
visr and Hofer-Julian authored Nov 10, 2023
1 parent edf50d0 commit c78995e
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 94 deletions.
7 changes: 6 additions & 1 deletion build/create_binaries/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Create Binaries


Build the app with:

```
Expand All @@ -12,3 +11,9 @@ Build the shared library with:
```
pixi run build-libribasim
```

Build both with:

```
pixi run build
```
20 changes: 20 additions & 0 deletions build/create_binaries/build.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using create_binaries

"""
Build the Ribasim CLI, libribasim, or both, using PackageCompiler.
Run from the command line with:
julia --project build.jl --app --lib
"""
function main(ARGS)
# change directory to this script's location
cd(@__DIR__)

if "--app" in ARGS
build_app()
elseif "--lib" in ARGS
build_lib()
end
end

main(ARGS)
39 changes: 0 additions & 39 deletions build/create_binaries/create_app.jl

This file was deleted.

24 changes: 0 additions & 24 deletions build/create_binaries/create_lib.jl

This file was deleted.

File renamed without changes.
32 changes: 32 additions & 0 deletions build/create_binaries/src/create_app.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"Build the Ribasim CLI using PackageCompiler"
function build_app()
project_dir = "../ribasim_cli"
license_file = "../../LICENSE"
output_dir = "ribasim_cli"
git_repo = "../.."

create_app(
project_dir,
output_dir;
# map from binary name to julia function name
executables = ["ribasim" => "julia_main"],
precompile_execution_file = "precompile.jl",
include_lazy_artifacts = true,
force = true,
)

add_metadata(project_dir, license_file, output_dir, git_repo)

# On Windows, write ribasim.cmd in the output_dir, that starts ribasim.exe.
# Since the bin dir contains a julia.exe and many DLLs that you may not want in your path,
# with this script you can put output_dir in your path instead.
if Sys.iswindows()
cmd = raw"""
@echo off
"%~dp0bin\ribasim.exe" %*
"""
open(normpath(output_dir, "ribasim.cmd"); write = true) do io
print(io, cmd)
end
end
end
17 changes: 14 additions & 3 deletions build/create_binaries/src/create_binaries.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
__precompile__(false)
module create_binaries

# This is not really a package, but needs to be set up like one so we can run
# `dev build/create_binaries` from the root project.
using Artifacts
using PackageCompiler
using TOML
using LibGit2

export build_app, build_lib

include("strip_cldr.jl")
include("add_metadata.jl")
include("create_app.jl")
include("create_lib.jl")

end
18 changes: 18 additions & 0 deletions build/create_binaries/src/create_lib.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"Build libribasim using PackageCompiler"
function build_lib()
project_dir = "../libribasim"
license_file = "../../LICENSE"
output_dir = "libribasim"
git_repo = "../.."

create_library(
project_dir,
output_dir;
lib_name = "libribasim",
precompile_execution_file = "precompile.jl",
include_lazy_artifacts = true,
force = true,
)

add_metadata(project_dir, license_file, output_dir, git_repo)
end
25 changes: 25 additions & 0 deletions build/create_binaries/src/strip_cldr.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
The cldr artifact has such long paths that it errors on Windows unless long paths are enabled.
Also the artifact has many files and is over 300 MB, while we only need a single small file.
This modifies the artifact to remove everything except the file we need.
Since the artifact is only used on Windows, only strip do it there.
This needs exactly TimeZones 1.13.0, which is fixed in the Project.toml.
https://github.com/JuliaTime/TimeZones.jl/issues/373
"""
function strip_cldr()
if Sys.iswindows()
# Get the artifact directory and the file path we need to keep
hash = Base.SHA1("40b35727ea0aff9a9f28b7454004b68849caf67b")
@assert artifact_exists(hash)
artifact_dir = artifact_path(hash)
keep_file =
normpath(artifact_dir, "cldr-release-43-1/common/supplemental/windowsZones.xml")
@assert isfile(keep_file)

# Read the file into memory, empty the artifact dir, and write the file back
keep_file_content = read(keep_file)
rm(artifact_dir; recursive = true)
mkpath(dirname(keep_file))
write(keep_file, keep_file_content)
end
end
24 changes: 0 additions & 24 deletions build/create_binaries/strip_cldr.jl

This file was deleted.

9 changes: 6 additions & 3 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ lint = { depends_on = [
"mypy-ribasim-api",
] }
# Build
build-ribasim-cli = { cmd = "cd build/create_binaries && julia --project create_app.jl", depends_on = [
build-ribasim-cli = { cmd = "cd build/create_binaries && julia --project build.jl --app", depends_on = [
"generate-testmodels",
"instantiate-julia",
] }
build-libribasim = { cmd = "cd build/create_binaries && julia --project create_lib.jl", depends_on = [
build-libribasim = { cmd = "cd build/create_binaries && julia --project build.jl --lib", depends_on = [
"generate-testmodels",
"instantiate-julia",
] }
build = { "cmd" = "julia --project build.jl --app --lib", cwd = "build/create_binaries", depends_on = [
"generate-testmodels",
"instantiate-julia",
] }
build = { depends_on = ["build-ribasim-cli", "build-libribasim"] }
# Test
test-ribasim-python = "pytest --numprocesses=auto python/ribasim/tests"
test-ribasim-api = "pytest --basetemp=python/ribasim_api/tests/temp --junitxml=report.xml python/ribasim_api/tests"
Expand Down

0 comments on commit c78995e

Please sign in to comment.