Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: include additional binaries in the fmu increasing portability #137

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
26 changes: 25 additions & 1 deletion pythonfmu/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def build_FMU(
dest: FilePath = ".",
project_files: Iterable[FilePath] = set(),
documentation_folder: Optional[FilePath] = None,
binary_files : Optional[FilePath] = None,
**options,
) -> Path:
script_file = Path(script_file)
Expand Down Expand Up @@ -164,14 +165,30 @@ def build_FMU(
src_binaries.rglob("*.so"),
src_binaries.rglob("*.dylib"),
):
relative_f = f.relative_to(src_binaries)
relative_f = f.relative_to(src_binaries)
arcname = (
binaries
/ relative_f.parent
/ f"{model_identifier}{relative_f.suffix}"
)
zip_fmu.write(f, arcname=arcname)

if binary_files is not None:
binary_file = Path(binary_files)
if binary_file.is_file():
with open(binary_file,'r') as bf:
bfs = bf.readlines()
bfs = [line.rstrip() for line in bfs]

for f in bfs:
f = Path(f)
arcname = (
binaries
/ get_platform()
/ f.name
)
zip_fmu.write(f, arcname=arcname)

# Add the documentation folder
if documentation_folder is not None:
documentation = Path("documentation")
Expand Down Expand Up @@ -217,6 +234,13 @@ def create_command_parser(parser: argparse.ArgumentParser):
default=None
)

parser.add_argument(
"--binary_file",
dest="binary_files",
help="will copy the files list in the binary file in binary folder enabling better portability",
default=None
)

for option in FMI2_MODEL_OPTIONS:
action = "store_false" if option.value else "store_true"
parser.add_argument(
Expand Down
3 changes: 3 additions & 0 deletions pythonfmu/pythonfmu-export/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ set(sources
pythonfmu/PySlaveInstance.cpp
)

SET (CMAKE_SHARED_LINKER_FLAGS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be UNIX only?

"${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,'$ORIGIN'")

add_library(pythonfmu-export ${sources} ${headers})
target_compile_features(pythonfmu-export PUBLIC "cxx_std_17")

Expand Down