Skip to content

Commit d08ef66

Browse files
authored
Merge pull request #262 from Robbybp/relocatable-libs
Make sure distributed libraries are relocatable
2 parents efb4af2 + 5013cc9 commit d08ef66

File tree

9 files changed

+236
-130
lines changed

9 files changed

+236
-130
lines changed

Diff for: doc/build-local.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Building IDAES binaries locally
2+
3+
For testing purposes, it may be useful to build the binaries locally, i.e. not
4+
using the Docker build scripts. This is also necessary for the MacOS builds
5+
(see the MacOS section in `build.md` for more information).
6+
7+
You can build locally by running the following scripts:
8+
9+
- `scripts/compile_solvers.sh`: Compile solvers (including `k_aug`, `dot_sens`,
10+
`petsc`, and all solver-associated libraries).
11+
- `scripts/compile_libs.sh`: Compile shared libraries for external functions.
12+
13+
It is recommended to perform an "out-of-source" build. This can be done by
14+
first running `scripts/build_directory.sh _build` from the top level of this
15+
repository. This copies source code, makefiles, patch files, and build scripts
16+
into the `_build` directory, where you will actually run the build.
17+
Move into the build directory with `cd _build`.
18+
19+
The build scripts were not designed for local use, so there are a few gotchas:
20+
21+
- We look for patch files in a specific location relative to the original
22+
working directory. I.e. you must run `compile_solvers.sh` from *one level above*
23+
the scripts directory in order for patches (e.g. `ipopt.pc.patch`) to be
24+
correctly applied.
25+
- `ipopt.pc.patch` assumes that `coinmumps` and `coinhsl` are listed as
26+
dependencies in the `ipopt.pc` file. If either is not found (i.e. we are
27+
compiling without HSL), the patch application will fail.
28+
- By default, Petsc is assumed to be installed in hard-coded, OS-dependent
29+
location. If you are compiling locally, you have probably installed it
30+
in your own preferred location. To override the default, set the `PETSC_DIR`
31+
environment variable to the location where you have installed Petsc.
32+
- If you have your own system-installed HSL libraries that are discoverable
33+
by the linker (i.e. `LD_LIBRARY_PATH` is set), the COIN-OR solvers will likely
34+
be able to find and link against them. In this case, you will see a
35+
`HSL Present: NO` message (as there was no `coinhsl.zip` in the parent of the
36+
working directory), but will likely still build HSL-enabled solvers.

Diff for: doc/build.md

+20
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,26 @@ Test on clean VM for now, hopfully GitHub actions runners will be available soon
114114

115115
There is a GitHub actions test.
116116

117+
## Testing a non-default branch
118+
119+
By default, the Docker driver scripts (`docker/build.sh` and `docker\build.ps1`)
120+
checkout the `main` branch of `https://github.com/idaes/idaes-ext.git` to use
121+
for the build process. To test a different branch, arguments can be provided
122+
to the Docker driver scripts. For example, to test the `ubuntu2204` build with
123+
a custom branch called `mybranch` on `user`'s fork, run
124+
```bash
125+
./build.sh ubuntu2204 https://github.com/user/idaes-ext.git mybranch
126+
```
127+
To test the Windows build, run
128+
```powershell
129+
.\build.ps1 windows --no-cache https://github.com/user/idaes-ext.git mybranch
130+
```
131+
Note that the second argument to `build.ps1` is interpreted as an argument
132+
to `docker build`, so to run with a custom branch and no such argument, run
133+
```powershell
134+
.\build.ps1 windows https://github.com/user/idaes-ext.git mybranch
135+
```
136+
117137
## Release Hashes
118138

119139
Collect all the tar files for a release in the same directory.

Diff for: docker/build-extensions/build.ps1

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
$flavor = $args[0]
22
$buildarg_1 = $args[1] # just use this to pass in --no-cache or some such
33

4-
$repo = "https://github.com/idaes/idaes-ext.git"
5-
$branch = "main"
4+
# The 3rd and 4th arguments provided will be interpreted as repo and branch.
5+
# (If you don't want to use buildarg_1, just pass in an empty string.)
6+
$repo = $args[2]
7+
$branch = $args[3]
8+
9+
# If repo and branch are not provided, use default values
10+
IF ($repo -eq $null){
11+
$repo = "https://github.com/idaes/idaes-ext.git"
12+
}
13+
IF ($branch -eq $null){
14+
$branch = "main"
15+
}
16+
617
$mname = "x86_64"
718

819
IF ($flavor -eq "windows"){
@@ -35,19 +46,13 @@ docker build --rm ${buildarg_1} --build-arg repo=${repo} --build-arg branch=${br
3546
Remove-Item extras -Recurse -Force -Confirm:$false
3647
docker run --name ${flavor}_build_tmp -dt ${flavor}_build_itmp:latest
3748
docker stop ${flavor}_build_tmp
38-
docker cp ${flavor}_build_tmp:${wdir}/idaes-ext/dist-lib/idaes-lib-${flavor}-${mname}.tar.gz .
49+
docker cp ${flavor}_build_tmp:${wdir}/idaes-ext/dist-functions/idaes-functions-${flavor}-${mname}.tar.gz .
3950
try{
40-
docker cp ${flavor}_build_tmp:${wdir}/idaes-ext/dist-solvers/idaes-solvers-${flavor}-${mname}.tar.gz .
51+
docker cp ${flavor}_build_tmp:${wdir}/idaes-ext/dist/idaes-solvers-${flavor}-${mname}.tar.gz .
4152
}
4253
catch{
4354
echo "Solvers were not built."
4455
}
45-
try{
46-
docker cp ${flavor}_build_tmp:${wdir}/idaes-ext/dist-petsc/idaes-petsc-${flavor}-${mname}.tar.gz .
47-
}
48-
catch{
49-
echo "PETSc was not built."
50-
}
5156
docker rm ${flavor}_build_tmp
5257
docker rmi ${flavor}_build_itmp
5358
cp *.tar.gz ../tarballs/

Diff for: docker/build-extensions/build.sh

100644100755
+17-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
flavor=$1
22
mname=$2
33

4-
repo="https://github.com/idaes/idaes-ext.git"
5-
branch="main"
4+
repo=$3
5+
branch=$4
6+
if [ ! "$repo" ]; then
7+
repo="https://github.com/idaes/idaes-ext.git"
8+
fi
9+
if [ ! "$branch" ]; then
10+
branch="main"
11+
fi
12+
13+
echo "build.sh script arguments:
14+
OS: $flavor
15+
Arch: $mname
16+
Repo: $repo
17+
Branch: $branch
18+
"
619

720
if [ "$flavor" = "windows" ]; then
821
image="idaes-ext-windows-build:latest"
@@ -37,9 +50,8 @@ docker exec "$flavor"_"$mname"_build_tmp sh -c "cd ${wdir}/idaes-ext && bash scr
3750
docker exec "$flavor"_"$mname"_build_tmp sh -c "cd ${wdir}/idaes-ext && bash scripts/compile_libs.sh ${flavor}"
3851
docker stop "$flavor"_"$mname"_build_tmp
3952

40-
docker cp "$flavor"_"$mname"_build_tmp:"$wdir"/idaes-ext/dist-lib/idaes-lib-"$flavor"-"$mname".tar.gz .
41-
docker cp "$flavor"_"$mname"_build_tmp:"$wdir"/idaes-ext/dist-solvers/idaes-solvers-"$flavor"-"$mname".tar.gz .
42-
docker cp "$flavor"_"$mname"_build_tmp:"$wdir"/idaes-ext/dist-petsc/idaes-petsc-"$flavor"-"$mname".tar.gz .
53+
docker cp "$flavor"_"$mname"_build_tmp:"$wdir"/idaes-ext/dist-functions/idaes-functions-"$flavor"-"$mname".tar.gz .
54+
docker cp "$flavor"_"$mname"_build_tmp:"$wdir"/idaes-ext/dist/idaes-solvers-"$flavor"-"$mname".tar.gz .
4355

4456
docker rm "$flavor"_"$mname"_build_tmp
4557

Diff for: scripts/compile_libs.sh

+21-19
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,32 @@ make
3030
cd $IDAES_EXT
3131

3232
# Collect files
33-
rm -rf ./dist-lib
34-
mkdir dist-lib
35-
cd dist-lib
36-
cp ../src/dist/*.so ./
33+
rm -rf ./dist-functions
34+
mkdir dist-functions dist-functions/lib
35+
#cd dist-functions
36+
cp ./src/dist/*.so ./dist-functions/lib/
3737
if [ ${osname} = "windows" ]; then
38-
mv functions.so functions.dll
39-
mv general_helmholtz_external.so general_helmholtz_external.dll
40-
mv cubic_roots.so cubic_roots.dll
38+
mv dist-functions/lib/functions.so dist-functions/lib/functions.dll
39+
mv dist-functions/lib/general_helmholtz_external.so dist-functions/lib/general_helmholtz_external.dll
40+
mv dist-functions/lib/cubic_roots.so dist-functions/lib/cubic_roots.dll
4141
fi
4242
if [ ${osname} = "darwin" ]; then
43-
mv functions.so functions.dylib
44-
mv general_helmholtz_external.so general_helmholtz_external.dylib
45-
mv cubic_roots.so cubic_roots.dylib
43+
mv dist-functions/lib/functions.so dist-functions/lib/functions.dylib
44+
mv dist-functions/lib/general_helmholtz_external.so dist-functions/lib/general_helmholtz_external.dylib
45+
mv dist-functions/lib/cubic_roots.so dist-functions/lib/cubic_roots.dylib
4646
fi
47-
cp ../license.txt ./license_lib.txt
48-
cp ../version.txt ./version_lib.txt
49-
mkdir ./helm_data
50-
cp ../src/dist/param_data/*.json ./helm_data/
51-
cp ../src/dist/param_data/*.nl ./helm_data/
52-
cp ../src/dist/param_data/*.py ./helm_data/
53-
sed s/"(DATE)"/`date +%Y%m%d-%H%M`/g version_lib.txt > tmp
47+
cp ./license.txt ./dist-functions/license_lib.txt
48+
cp ./version.txt ./dist-functions/version_lib.txt
49+
mkdir ./dist-functions/lib/helm_data
50+
cp ./src/dist/param_data/*.json ./dist-functions/lib/helm_data/
51+
cp ./src/dist/param_data/*.nl ./dist-functions/lib/helm_data/
52+
cp ./src/dist/param_data/*.py ./dist-functions/lib/helm_data/
53+
sed s/"(DATE)"/`date +%Y%m%d-%H%M`/g dist-functions/version_lib.txt > tmp
5454
sed s/"(PLAT)"/${osname}-${MNAME}/g tmp > tmp2
55-
mv tmp2 version_lib.txt
55+
mv tmp2 dist-functions/version_lib.txt
5656
rm tmp
5757

5858
# here you pack files
59-
tar -czvf idaes-lib-${osname}-${MNAME}.tar.gz *
59+
cd dist-functions
60+
tar -czvf idaes-functions-${osname}-${MNAME}.tar.gz *
61+
cd $IDAES_EXT

0 commit comments

Comments
 (0)