Skip to content

Commit

Permalink
v0.4.0 (#34)
Browse files Browse the repository at this point in the history
* preparations for linux support, integration of new tests

* project.toml version inc
  • Loading branch information
ThummeTo authored Jan 23, 2025
1 parent 9d40af4 commit 40d8656
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FMIBuild"
uuid = "226f0e26-6dd6-4589-ada7-1d32f6e1d800"
authors = ["TT <tobias.thummerer@informatik.uni-augsburg.de>", "LM <lars.mikelsons@informatik.uni-augsburg.de>"]
version = "0.3.2"
version = "0.4.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand All @@ -12,6 +12,6 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
[compat]
Dates = "1"
FMIBase = "1.0.0"
PackageCompiler = "2.1.9"
PackageCompiler = "2.1.9, 2.2.0"
Pkg = "1"
julia = "1.6"
6 changes: 3 additions & 3 deletions src/FMIBuild.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ function saveFMU(fmu::FMU2, fmu_path::String, fmu_src_file::Union{Nothing, Strin

# [note] redirect FMIExport.jl package in case the active environment (the env the installer is called from)
# has a *more recent* version of FMIExport.jl than the registry (necessary for Github-CI to use the current version from a PR)
if isnothing(default_fmiexportPath) # the environemnt the exporter is called from *has no* FMIExport.jl installed
if isnothing(default_fmiexportPath) # the environment the exporter is called from *has no* FMIExport.jl installed
@info "[Build FMU] > Default environment `$(defaultEnv)` has no dependency on `FMIExport`."
else # the environemnt the exporter is called from *has* FMIExport.jl installed
else # the environment the exporter is called from *has* FMIExport.jl installed
old_fmiexportPath = packagePath("FMIExport")
if isnothing(old_fmiexportPath) # the FMU has no dependency to FMIExport.jl
@info "[Build FMU] > `FMIExport` for FMU not installed, adding at `$(default_fmiexportPath)`, adding `FMIExport` from default environment."
Expand Down Expand Up @@ -326,7 +326,7 @@ function saveFMU(fmu::FMU2, fmu_path::String, fmu_src_file::Union{Nothing, Strin
cp(key, joinpath(bin_dir, "..", "..", "resources", val); force=true)
@info "[Build FMU] \t $val"
end
@info "[Build FMU] ... adding resoruce files done."
@info "[Build FMU] ... adding resource files done."
end

@info "[Build FMU] Patching libjulia.$(libext) @ `$(bin_dir)`..."
Expand Down
54 changes: 48 additions & 6 deletions template/ME/header/FMU2_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,31 @@ void shutdown_julia(int retcode) { jl_atexit_hook(retcode); }

// custom

void constructor(short unsigned int* path)
{
init_julia(0, NULL);

char* ptr = (char*)&path;
init_FMU(ptr);
}

void destructor(void)
{
shutdown_julia(0);
}

#ifdef _WIN32
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
init_julia(0, NULL);

// get DLL path for resource location
char path[MAX_PATH];
short unsigned int path[MAX_PATH];
HMODULE hm = NULL;

if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR) &init_julia, &hm) == 0)
if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCWSTR) &init_julia, &hm) == 0)
{
int ret = GetLastError();
fprintf(stderr, "GetModuleHandle failed, error = %d\n", ret);
Expand All @@ -109,12 +122,41 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
return (FALSE);
}

char* ptr = (char*)&path;
init_FMU(ptr);
constructor(path);
break;
case DLL_PROCESS_DETACH:
shutdown_julia(0);
destructor();
break;
}
return (TRUE);
}

#else
CP_BEGIN_EXTERN_C
__attribute__((constructor))
/**
* initializer of the dylib.
*/
static void Initializer(int argc, char** argv, char** envp)
{
char pid[20];
char path[PATH_MAX + 1] = {0};

sprintf(pid, "/proc/%d/exe", getpid());
readlink(pid, path, sizeof(path));

constructor(string(path));
}

__attribute__((destructor))
/**
* It is called when dylib is being unloaded.
*
*/
static void Finalizer()
{
destructor();
}

CP_END_EXTERN_C
#endif

4 comments on commit 40d8656

@ThummeTo
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/123547

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.0 -m "<description of version>" 40d86569369d031e4d52be222ba7f0a56fcdf22a
git push origin v0.4.0

@ThummeTo
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Release notes:

Breaking changes

  • no interface changes, this is only breaking because of another version of C standard libraries

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request updated: JuliaRegistries/General/123547

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.0 -m "<description of version>" 40d86569369d031e4d52be222ba7f0a56fcdf22a
git push origin v0.4.0

Please sign in to comment.