Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion Manifest.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
JuliaC = "acedd4c2-ced6-4a15-accc-2607eb759ba2"
JuliaInterpreter = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down Expand Up @@ -80,6 +81,7 @@ TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
TranscodingStreams = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"

[sources]
JuliaC = {rev = "default_cpu_target", url = "https://github.com/visr/JuliaC.jl"}
PackageCompiler = {rev = "bundle_less_artifacts_v1.12", url = "https://github.com/visr/PackageCompiler.jl"}
Ribasim = {path = "core"}

Expand Down
75 changes: 50 additions & 25 deletions build/build.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
using Artifacts
using PackageCompiler
using TOML
using LibGit2
using JuliaC
using Preferences: set_preferences!, delete_preferences!
using UUIDs: UUID
import Pkg

function (@main)(_)::Cint
project_dir = "../core"
license_file = "../LICENSE"
output_dir = "ribasim"
git_repo = ".."

# change directory to this script's location
cd(@__DIR__)

create_library(
project_dir,
output_dir;
lib_name = "libribasim",
precompile_execution_file = "precompile.jl",
include_lazy_artifacts = false,
include_transitive_dependencies = false,
include_preferences = true,
force = true,
project_dir = "core"
license_file = "LICENSE"
output_dir = "build/ribasim"
git_repo = "."

# Set release options in core/LocalPreferences.toml
uuid = UUID("aac5e3d9-0b8f-4d4f-8241-b1a7a9632635") # Ribasim
Pkg.activate("core")
set_preferences!(uuid, "precompile_workload" => true; force = true)
Pkg.activate(".")

rm(output_dir; force = true, recursive = true)

image_recipe = ImageRecipe(;
output_type = "--output-lib",
file = "build/libribasim.jl",
project = project_dir,
add_ccallables = true,
verbose = true,
)
link_recipe = LinkRecipe(;
image_recipe,
outname = "build/ribasim/libribasim",
rpath = "@bundle"
)
bundle_recipe = BundleRecipe(; link_recipe, output_dir)

compile_products(image_recipe)
link_products(link_recipe)
bundle_products(bundle_recipe)

# On Windows, remove the import library from the bundle root
if Sys.iswindows()
import_lib_path = joinpath(output_dir, "libribasim.dll.a")
rm(import_lib_path)
end

add_metadata(project_dir, license_file, output_dir, git_repo, readme_start)

Expand All @@ -33,10 +53,16 @@ function (@main)(_)::Cint
env["RUSTFLAGS"] = "-C link-args=/STACK:8388608"
end

run(Cmd(`cargo build --release`; dir = "cli", env))
run(Cmd(`cargo build --release`; dir = "build/cli", env))
ribasim = Sys.iswindows() ? "ribasim.exe" : "ribasim"
mkpath("ribasim/bin")
cp("cli/target/release/$ribasim", "ribasim/bin/$ribasim"; force = true)
mkpath("build/ribasim/bin")
cp("build/cli/target/release/$ribasim", "build/ribasim/bin/$ribasim"; force = true)

# Restore development options in core/LocalPreferences.toml
Pkg.activate("core")
delete_preferences!(uuid, "precompile_workload"; force = true)
Pkg.activate(".")

return 0
end

Expand Down Expand Up @@ -78,8 +104,7 @@ function add_metadata(project_dir, license_file, output_dir, git_repo, readme)
TOML.print(io, dict)
end

# a stripped Project.toml is already added in the same location by PackageCompiler
# however it is better to copy the original, since it includes the version and compat
# Copy the Project.toml and Manifest.toml so we can see all dependencies and versions
cp(
normpath(project_dir, "Project.toml"),
normpath(output_dir, "share/julia/Project.toml");
Expand Down Expand Up @@ -129,5 +154,5 @@ function add_metadata(project_dir, license_file, output_dir, git_repo, readme)
end

# Override the Cargo.toml file with the git version
return set_version("cli/Cargo.toml", tag)
return set_version("build/cli/Cargo.toml", tag)
end
6 changes: 1 addition & 5 deletions core/src/libribasim.jl → build/libribasim.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module libribasim

import BasicModelInterface as BMI
import ..Ribasim
import Ribasim
using SciMLBase: successful_retcode

# globals
Expand Down Expand Up @@ -233,5 +231,3 @@ function unsafe_write_to_cstring!(dest::Cstring, src::String)::Nothing
unsafe_store!(dest_ptr, '\0', length(src) + 1)
return nothing
end

end # module libribasim
16 changes: 0 additions & 16 deletions build/precompile.jl

This file was deleted.

3 changes: 0 additions & 3 deletions core/src/Ribasim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ using Printf: @sprintf

using Base.Threads: nthreads

export libribasim

include("carrays.jl")
using .CArrays: CVector, getaxes, getdata
include("schema.jl")
Expand All @@ -193,7 +191,6 @@ include("bmi.jl")
include("callback.jl")
include("concentration.jl")
include("main.jl")
include("libribasim.jl")

@setup_workload begin
toml_path = normpath(@__DIR__, "../../generated_testmodels/basic/ribasim.toml")
Expand Down
6 changes: 5 additions & 1 deletion core/test/libribasim_test.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
@testitem "libribasim" begin
@testmodule libribasim begin
include("../../build/libribasim.jl")
end

@testitem "libribasim" setup = [libribasim] begin
toml_path = normpath(@__DIR__, "../../generated_testmodels/basic/ribasim.toml")

# data from which we create pointers for libribasim
Expand Down
2 changes: 1 addition & 1 deletion pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ lint = { depends-on = [
"mypy-ribasim-qgis",
] }
# Build
build = { "cmd" = "julia --project --check-bounds=yes build.jl", cwd = "build", depends-on = [
build = { "cmd" = "julia --project --check-bounds=yes build/build.jl", depends-on = [
"generate-testmodels",
"initialize-julia",
] }
Expand Down
Loading