Recommended workflow to prepare a package to use it as a dll with PackageCompiler.jl

I am currently trying to compile one of my packages for use as dll with PackageCompiler.jl.
This somewhat a follow up post of Package Compiler error when reproducing documentation example, yet more generic.

During the aforementioned discussion it seems that to use a package as a dll one has to perform multiple modifications with respect to the initial pure julia code. Among these modifications, I can think of :

  • change julia types to C understandable types, for both input and return values
  • decorate function declarations using the Base.@ccallable macro

The general question about these modifications (and the probable others I did not think about) is : how to make them as transparent or painless as possible for the user ?

In fact, most examples I read to export a C-usable function mention scalar types, e.g.

Base.@ccallable function my_main_function(x::Cfloat,y::Cfloat)::Cfloat
        z = 0
        for i in 1:x
            z += i ^ y
        end
        return z
    end

I can only assume that the initial function was something like

function my_main_function(x::Float32,y::Float32)::Float32
        z = 0
        for i in 1:x
            z += i ^ y
        end
        return z
    end

From this basic example, some questions arise :

  • How to avoid coding twice every function ?
    If the input and return types are explicitly declared, this function can only be used with Ctypes. But when developping the julia package it seems less than ideal to be unable to use julia types when trying such functions.
  • How to handle array type, or structs conversion ?
    When packages become more complex, and structures are used to pass multiple data to different functions, how to avoid all the manual type conversion ? It may be a job for Base.cconvert or Base.unsafe_convert, but that’s a highly dubious guess

These points may have been addressed before, but after having spent multiple days on this, it is still very unclear to me what the correct workflow should be.