ThummeTo / FMIBuild.jl

FMIBuild.jl holds dependencies that are required to compile and zip a Functional Mock-Up Unit (FMU) compliant to the FMI-standard (fmi-standard.org). Because this dependencies should not be part of the compiled FMU, they are out-sourced into this package. FMIBuild.jl provides the build-commands for the Julia package FMIExport.jl.
MIT License
10 stars 2 forks source link

Linux-compatible FMU generation #25

Open CasBex opened 1 year ago

CasBex commented 1 year ago

Hi there. I've been trying to export the BouncingBall example in FmiExport.jl but this fails with the following error:

[ Info: Saving example files at: /tmp/fmibuildjl_test_pT3ZdP
[ Info: [Build FMU] Automatically determined build file at: `/home/cas/tmp/FMIExport.jl/example/FMI2/BouncingBall/src/BouncingBall.jl`.
[ Info: [Build FMU] Generating package ...
[ Info: [Build FMU] Source package is /home/cas/tmp/FMIExport.jl/example/FMI2/BouncingBall, deployed at /tmp/fmibuildjl_axGCIh/merged_BouncingBall
[ Info: [Build FMU] Relative src file path is src/BouncingBall.jl
[ Info: [Build FMU] ... reading FMU template file at /home/cas/.julia/packages/FMIBuild/y2TgX/src/../template/ME/FMU2/src/FMU2_content.jl
[ Info: [Build FMU] ... reading old FMU source file at /tmp/fmibuildjl_axGCIh/merged_BouncingBall/src/BouncingBall.jl
[ Info: [Build FMU] Removing `FMIBUILD_NO_EXPORT_*` blocks ...
[ Info: [Build FMU] ... removed `FMIBUILD_NO_EXPORT_*` blocks.
[ Info: [Build FMU] Adding/removing dependencies ...
  Activating project at `/tmp/fmibuildjl_axGCIh/merged_BouncingBall`
[ Info: [Build FMU]    > Most recent version of `FMIExport` already checked out, is `/home/cas/.julia/packages/FMIExport/Fq22B`.
   Resolving package versions...
    Updating `/tmp/fmibuildjl_axGCIh/merged_BouncingBall/Project.toml`
  [8af89139] + FMICore v0.17.2
  No Changes to `/tmp/fmibuildjl_axGCIh/merged_BouncingBall/Manifest.toml`
[ Info: [Build FMU]    > Added `FMICore`
    Updating `/tmp/fmibuildjl_axGCIh/merged_BouncingBall/Project.toml`
  [226f0e26] - FMIBuild v0.1.15
    Updating `/tmp/fmibuildjl_axGCIh/merged_BouncingBall/Manifest.toml`
  [226f0e26] - FMIBuild v0.1.15
  [9b87118b] - PackageCompiler v2.1.7
  [05181044] - RelocatableFolders v1.0.0
  [6c6a2e73] - Scratch v1.2.0
  [a5390f91] - ZipFile v0.10.1
  [4af54fe1] - LazyArtifacts
[ Info: [Build FMU]    > Removed FMIBuild
  Activating project at `~/tmp/FMIExport.jl/example/FMI2/BouncingBall`
[ Info: [Build FMU] ... adding/removing dependencies done.
[ Info: [Build FMU] ... generating new FMU source file at /tmp/fmibuildjl_axGCIh/merged_BouncingBall/src/BouncingBall.jl
[ Info: [Build FMU] ... generating package done.
[ Info: [Build FMU] Compiling FMU ...
[ Warning: PackageCompiler: This does not look like an official Julia build, functionality may suffer.
PackageCompiler: bundled artifacts:
  ├── Libiconv_jll - 3.674 MiB
  └── XML2_jll - 5.872 MiB
  Total artifact file size: 9.545 MiB
✔ [02m:15s] PackageCompiler: compiling base system image (incremental=false)
✔ [02m:59s] PackageCompiler: compiling nonincremental system image
Precompiling project...
  11 dependencies successfully precompiled in 6 seconds
[ Info: PackageCompiler: Executing /tmp/fmibuildjl_axGCIh/merged_BouncingBall/src/BouncingBall.jl => /tmp/jl_packagecompiler_OKjrQk/jl_RcdzTu
[ Info: PackageCompiler: Done
✔ [01m:18s] PackageCompiler: compiling incremental system image
In file included from /home/cas/.julia/packages/FMIBuild/y2TgX/src/../template/ME/header/FMU2_init.c:19:
/home/cas/.julia/packages/FMIBuild/y2TgX/src/../template/ME/header/FMU2_init.h:104:10: fatal error: WinDef.h: No such file or directory
  104 | #include <WinDef.h>
      |          ^~~~~~~~~~
compilation terminated.
ERROR: LoadError: failed process: Process(`gcc -c -O2 '-DJULIAC_PROGRAM_LIBNAME="libBouncingBall.so"' -DNEW_DEFINE_FAST_TLS_SYNTAX -m64 -std=gnu99 -I/usr/include/julia -fPIC -march=x86-64 -o /home/cas/.julia/packages/FMIBuild/y2TgX/src/../template/ME/header/FMU2_init.o /home/cas/.julia/packages/FMIBuild/y2TgX/src/../template/ME/header/FMU2_init.c`, ProcessExited(1)) [1]

Stacktrace:
  [1] run
    @ ./process.jl:477 [inlined]
  [2] run_compiler(cmd::Cmd; cplusplus::Bool)
    @ PackageCompiler ~/.julia/packages/PackageCompiler/b2smD/src/PackageCompiler.jl:194
  [3] run_compiler
    @ ~/.julia/packages/PackageCompiler/b2smD/src/PackageCompiler.jl:190 [inlined]
  [4] compile_c_init_julia(julia_init_c_file::String, sysimage_name::String)
    @ PackageCompiler ~/.julia/packages/PackageCompiler/b2smD/src/PackageCompiler.jl:665
  [5] create_sysimage(packages::Vector{String}; sysimage_path::String, project::String, precompile_execution_file::Vector{String}, precompile_statements_file::Vector{String}, incremental::Bool, filter_stdlibs::Bool, cpu_target::String, script::Nothing, sysimage_build_args::Cmd, include_transitive_dependencies::Bool, base_sysimage::String, julia_init_c_file::String, version::Nothing, soname::String, compat_level::String, extra_precompiles::String)
    @ PackageCompiler ~/.julia/packages/PackageCompiler/b2smD/src/PackageCompiler.jl:598
  [6] create_sysimage_workaround(ctx::Pkg.Types.Context, sysimage_path::String, precompile_execution_file::Vector{String}, precompile_statements_file::Vector{String}, incremental::Bool, filter_stdlibs::Bool, cpu_target::String; sysimage_build_args::Cmd, include_transitive_dependencies::Bool, julia_init_c_file::String, version::Nothing, soname::String, script::Nothing)
    @ PackageCompiler ~/.julia/packages/PackageCompiler/b2smD/src/PackageCompiler.jl:1072
  [7] create_sysimage_workaround
    @ ~/.julia/packages/PackageCompiler/b2smD/src/PackageCompiler.jl:1045 [inlined]
  [8] create_library(package_dir::String, dest_dir::String; lib_name::String, precompile_execution_file::Vector{String}, precompile_statements_file::Vector{String}, incremental::Bool, filter_stdlibs::Bool, force::Bool, header_files::Vector{String}, julia_init_c_file::String, version::Nothing, compat_level::String, cpu_target::String, include_lazy_artifacts::Bool, sysimage_build_args::Cmd, include_transitive_dependencies::Bool, script::Nothing)
    @ PackageCompiler ~/.julia/packages/PackageCompiler/b2smD/src/PackageCompiler.jl:992
  [9] create_library
    @ ~/.julia/packages/PackageCompiler/b2smD/src/PackageCompiler.jl:941 [inlined]
 [10] fmi2Save(fmu::FMICore.FMU2, fmu_path::String, fmu_src_file::Nothing; standalone::Bool, compress::Bool, cleanup::Bool, removeLibDependency::Bool, removeNoExportBlocks::Bool, resources::Nothing, surpressWarnings::Bool, debug::Bool, pkg_comp_kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ FMIBuild ~/.julia/packages/FMIBuild/y2TgX/src/FMIBuild.jl:294
 [11] fmi2Save
    @ ~/.julia/packages/FMIBuild/y2TgX/src/FMIBuild.jl:68 [inlined]
 [12] fmi2Save(fmu::FMICore.FMU2, fmu_path::String)
    @ FMIBuild ~/.julia/packages/FMIBuild/y2TgX/src/FMIBuild.jl:68
 [13] top-level scope
    @ ~/tmp/FMIExport.jl/example/FMI2/BouncingBall/src/BouncingBall.jl:138
 [14] include(fname::String)
    @ Base.MainInclude ./client.jl:478
 [15] top-level scope
    @ REPL[2]:1
in expression starting at /home/cas/tmp/FMIExport.jl/example/FMI2/BouncingBall/src/BouncingBall.jl:138

I don't really know how to fix this. In template/ME/FMU2_init.h it says the code is windows specific (I'm using Fedora38) and I think that is the problem? Are there any plans to make the fmu-generation linux compatible? Or am I missing something obvious?

EDIT: I have tried generating BouncingBall.fmu on a Windows machine and this did work

ThummeTo commented 1 year ago

This is exactly the problem, currently this only works on Windows because we are using a Windows-library (DLL-specific) in the considered file. This could be fixed by adding a Linux-equivalent for the FMU2_init.h-file and using the Linux-Version for islinux() == true during export. Further a solution for this is on todo, but with lower priority, so if this is urgent I have no problem and would appreciate if anyone else wants to contribute :)

CasBex commented 1 year ago

Alright, thanks for the clarification. It's currently not very urgent and my C skills are not up to the task, but maybe later a solution will be coming your way :)