diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml new file mode 100644 index 0000000..e649a09 --- /dev/null +++ b/.github/workflows/test_dev.yml @@ -0,0 +1,61 @@ +name: Development Tests + +on: + schedule: + - cron: 0 0 * * * + workflow_dispatch: + push: + paths: + - '.github/**' + - 'test/CoolPropDevLoader/**' + +permissions: + contents: read + + concurrency: + # Skip intermediate builds: all builds except for builds on the `master` branch + # Cancel intermediate builds: only pull request builds + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.ref != 'refs/heads/master' || github.run_number }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} + +jobs: + test-coolprop-dev: + timeout-minutes: 30 + strategy: + matrix: + julia_version: + - '1.12' + os: + - ubuntu-latest + julia_arch: + - x64 + fail-fast: false + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout + uses: actions/checkout@v7 + + - uses: julia-actions/setup-julia@v3 + with: + arch: ${{ matrix.julia_arch }} + version: ${{ matrix.julia_version }} + - uses: julia-actions/cache@v3 + + - name: add CoolPropDevLoader + shell: julia --color=yes --project=. {0} + run: | + using Pkg + Pkg.develop(path="test/CoolPropDevLoader") + + - name: Compiling CoolProp + shell: julia --color=yes --compiled-modules=no --project=test {0} + run: | + using Pkg + Pkg.develop(path="test/CoolPropDevLoader") + using CoolPropDevLoader + CoolPropDevLoader.use_dev_library(CoolPropDevLoader.CompileCoolPropFromSourceforge()) + Pkg.add("Test") + + - uses: julia-actions/julia-runtest@v1 + \ No newline at end of file diff --git a/Project.toml b/Project.toml index 8d3eb71..5ed719e 100644 --- a/Project.toml +++ b/Project.toml @@ -5,12 +5,14 @@ version = "0.2.2" [deps] CoolProp_jll = "3351c21f-4feb-5f29-afb9-f4fcb0e27549" Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" +Preferences = "21216c6a-2e73-6563-6e65-726566657250" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [compat] CoolProp_jll = "6.6, 7.1" julia = "1.3" -Unitful="1" +Preferences = "1" +Unitful = "1" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/README.md b/README.md index 68a2f27..5d6d768 100644 --- a/README.md +++ b/README.md @@ -38,4 +38,4 @@ using Unitful: °C, Pa HAPropsSI("H", "Tdb", 20°C, "RH", 0.5, "P", 101325Pa) 38622.83892391293 J kg⁻¹ -``` +``` \ No newline at end of file diff --git a/src/CoolProp.jl b/src/CoolProp.jl index 9a7b964..abe5afb 100644 --- a/src/CoolProp.jl +++ b/src/CoolProp.jl @@ -1,8 +1,20 @@ #__precompile__() module CoolProp + + import Unitful -using CoolProp_jll +import CoolProp_jll + +@static if VERSION >= v"1.6" + using Preferences +end + +@static if VERSION >= v"1.6" + const libcoolprop = load_preference(CoolProp_jll,"coolprop_library", CoolProp_jll.libcoolprop) +else + const libcoolprop = CoolProp_jll.libcoolprop +end #################################################################################################################### #################################################################################################################### diff --git a/test/CoolProp.jl b/test/CoolProp.jl index 46c7d51..0c36e6d 100644 --- a/test/CoolProp.jl +++ b/test/CoolProp.jl @@ -1,6 +1,8 @@ #__precompile__() module CoolProp +@info "CoolProp library path: $(CoolProp.libcoolprop)" + errcode = Ref{Clong}(0) const buffer_length = 20000 message_buffer = Array(UInt8, buffer_length) diff --git a/test/CoolPropDevLoader/Project.toml b/test/CoolPropDevLoader/Project.toml new file mode 100644 index 0000000..b2860ca --- /dev/null +++ b/test/CoolPropDevLoader/Project.toml @@ -0,0 +1,20 @@ +name = "CoolPropDevLoader" +uuid = "1abf7821-c65a-4ba0-83a4-5660520f37c7" +version = "1.0.0" + +[deps] +Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6" +Preferences = "21216c6a-2e73-6563-6e65-726566657250" +CoolProp_jll = "3351c21f-4feb-5f29-afb9-f4fcb0e27549" + +[compat] +Downloads = "1" +julia = "1.6" +Preferences = "1" +CoolProp_jll = "6.6, 7.1" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/test/CoolPropDevLoader/src/CoolPropDevLoader.jl b/test/CoolPropDevLoader/src/CoolPropDevLoader.jl new file mode 100644 index 0000000..0aa5750 --- /dev/null +++ b/test/CoolPropDevLoader/src/CoolPropDevLoader.jl @@ -0,0 +1,110 @@ +module CoolPropDevLoader + +using Preferences +using Downloads +using CoolProp_jll + +const SOURCEFORGE_URL = "https://sourceforge.net/projects/coolprop/files/CoolProp/nightly/source/CoolProp_sources.zip/download" + +#only available in linux +function compile_from_sourceforge() + # 1. Configuration + url = SOURCEFORGE_URL + build_dir = joinpath(@__DIR__, "coolprop_build") # Change as needed + source_zip = joinpath(build_dir, "CoolProp_sources.zip") + extract_dir = build_dir # We'll extract directly into build_dir, then locate source root + lib_name = "libCoolProp.so" + + # 2. Create build directory + mkpath(build_dir) + mkpath(extract_dir) + + # 3. Download the source zip + @info "Downloading CoolProp source from $url..." + Downloads.download(SOURCEFORGE_URL, source_zip) + + # 4. Extract the zip into build_dir + @info "Extracting source..." + run(`unzip -qo $source_zip -d $build_dir`) + + # 5. Find the actual source root: a directory that contains CMakeLists.txt + @info "Locating source root..." + function find_cmakelists_root(dir) + # Check if dir itself contains CMakeLists.txt + if isfile(joinpath(dir, "CMakeLists.txt")) + return dir + end + # Otherwise, look for a subdirectory that contains it + for entry in readdir(dir) + path = joinpath(dir, entry) + if isdir(path) && isfile(joinpath(path, "CMakeLists.txt")) + return path + end + end + # If not found, search recursively (but be careful with deep structures) + for (root, dirs, files) in walkdir(dir) + if "CMakeLists.txt" in files + return root + end + end + error("Could not find CMakeLists.txt anywhere in $dir") + end + + source_root = find_cmakelists_root(extract_dir) + @info "Source root found at: $source_root" + + # 6. Prepare for CMake build: create a build subdirectory inside source_root + build_subdir = joinpath(source_root, "build") + mkpath(build_subdir) + cd(build_subdir) do + # 7. Configure with CMake - build shared library + @info "Configuring with CMake..." + run(`cmake .. -DCOOLPROP_SHARED_LIBRARY=ON -DCMAKE_BUILD_TYPE=Release`) + + # 8. Build + @info "Compiling CoolProp (this may take a few minutes)..." + run(`cmake --build . --config Release --parallel $(Sys.CPU_THREADS)`) + end + + # 9. Locate the generated shared library + # The library is typically in build/ or build/Release/ or build/lib/ + possible_paths = [ + joinpath(source_root, "build", lib_name), + joinpath(source_root, "build", "Release", lib_name), + joinpath(source_root, "build", "lib", lib_name), + ] + + lib_path = nothing + for p in possible_paths + if isfile(p) + lib_path = p + break + end + end + + if lib_path === nothing + error("Could not find compiled library. Looked in: $(join(possible_paths, ", "))") + end + + @info "CoolProp library built successfully at: $lib_path" + return lib_path +end + +struct CompileCoolPropFromSourceforge end + +function use_dev_library(::CompileCoolPropFromSourceforge) + lib_src = compile_from_sourceforge() + set_preferences!(CoolProp_jll,"coolprop_library" => lib_src, force = true) + @info "Preference set to $lib_src" +end + +function use_dev_library(lib_src::String) + set_preferences!(CoolProp_jll,"coolprop_library" => lib_src, force = true) + @info "Preference set to $lib_src" +end + +function use_default_library() + delete_preferences!(CoolProp_jll,"coolprop_library",force = true,export_prefs = true) +end + +end #module \ No newline at end of file