Boilerplate helper for bundling native code
Switch branches/tags
Nothing to show
Latest commit f172f2b Nov 2, 2016 @hoelzro committed on GitHub Merge pull request #3 from zoffixznet/patch-1
Add mandatory "perl" META field
Failed to load latest commit information.
lib/Native Update documentation to mark this as deprecated Sep 2, 2016
LICENSE Add license Jan 8, 2016 Add mandatory "perl" META field Oct 26, 2016 POD rendering fix Sep 2, 2016



DEPRECATED Boilerplate helper for bundling native code


Rob Hoelz


        # assume you're building a helper library named 'helper'

        # in at the root of your distribution
        use Panda::Builder;
        use Native::Resources::Build;

        class Build is Panda::Builder {
            method build($workdir) {
                make($workdir, "$workdir/resources/lib", :libname<helper>);

        # in
        all: resources/lib/libhelper%SO% %FAKESO%

        # rest of Makefile rules

        # in
            ...other metadata...
            "resources": [

        # in lib/ (or whatever your module is called)
        use Native::Resources;
        use NativeCall;

        our sub call_helper() is native(resource-lib('helper', :%?RESOURCES)) { * }


Note: This module has served its purpose, but is no longer necessary; it is thus DEPRECATED. You can achieve the same effect by specifying resources under resources/libraries in your META6.json without any lib prefix or extension, and by retrieving that resource from %?RESOURCES in your module.

Most of the time when you use NativeCall, you can just refer to libraries that your OS has installed by default. However, sometimes, you want to bundle native libraries into your distribution. There are several reasons for doing this, among them are:

  • You have no guarantee that a library will be installed, or that it will be of the correct version, so you bundle your own
  • You're wrapping C++ code, which is tricky (or sometimes impossible) to do with NativeCall, so you need to write some C code to wrap the C++ into something NativeCall can use

This distribution provides two modules to help reduce the boilerplate you need to write for this situation. Native::Resources provides resource-lib, which consults your distribution's resources and determines the correct file to use. Native::Resources::Build provides a make subroutine meant to be called from at your distribution's root.



Copyright (c) 2016 Rob Hoelz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


sub resource-lib

sub resource-lib(
    Str $libname,
) returns Code

Returns a filename that corresponds to the given library (denoted by $libname). You need to pass your %?RESOURCES in so the sub knows where to look.