Bundlex v0.4.0 Bundlex.Project behaviour View Source

Behaviour that should be implemented by each project using Bundlex in the bundlex.exs file.

Link to this section Summary

Types

Type describing input project configuration.

Type describing configuration of a native.

t()

Struct representing bundlex project.

Functions

Returns the project struct of given application.

Determines if module is a bundlex project module.

Callbacks

Callback returning project configuration.

Link to this section Types

Link to this type

config_t()

View Source
config_t() ::
  Bunch.KVList.t(
    :natives | :libs,
    Bunch.KVList.t(native_name_t(), native_config_t())
  )

Type describing input project configuration.

It's a keyword list, where natives and libs can be specified. :nifs, :cnodes and :ports keys are deprecated. Instead, use :natives with proper :interfaces. Libs are native packages that are compiled as static libraries and linked to natives that have them specified in deps field of their configuration.

Link to this type

native_config_t()

View Source
native_config_t() :: [
  sources: [String.t()],
  includes: [String.t()],
  lib_dirs: [String.t()],
  libs: [String.t()],
  pkg_configs: [String.t()],
  deps: [{Application.app(), native_name_t() | [native_name_t()]}],
  src_base: String.t(),
  compiler_flags: [String.t()],
  linker_flags: [String.t()],
  language: :c | :cpp,
  interface:
    [Bundlex.Native.interface_t()] | Bundlex.Native.interface_t() | nil,
  preprocessor:
    [Bundlex.Project.Preprocessor.t()] | Bundlex.Project.Preprocessor.t()
]

Type describing configuration of a native.

It's a keyword list containing the following keys:

  • sources - C files to be compiled (at least one must be provided),
  • includes - Paths to look for header files (empty list by default).
  • lib_dirs - Paths to look for libraries (empty list by default).
  • libs - Names of libraries to link (empty list by default).
  • pkg_configs - Names of libraries for which the appropriate flags will be obtained using pkg-config (empty list by default).
  • deps - Dependencies in the form of {app, lib_name}, where app is the application name of the dependency, and lib_name is the name of lib specified in bundlex project of this dependency. See Dependencies section in readme for details.
  • src_base - Native files should reside in project_root/c_src/<src_base> (application name by default).
  • compiler_flags - Custom flags for compiler.
  • linker_flags - Custom flags for linker.
  • language - Language of native. :c or :cpp may be chosen (:c by default)
  • interface - Interface of native. It can be single atom e.g. :nif or list of atoms.
  • preprocessors - Modules implementing Bundlex.Project.Preprocessor behaviour
Link to this type

native_name_t()

View Source
native_name_t() :: atom()
Link to this type

t()

View Source
t() :: %Bundlex.Project{
  app: atom(),
  config: config_t(),
  module: module(),
  src_path: String.t()
}

Struct representing bundlex project.

Contains the following fileds:

  • :config - project configuration
  • :src_path - path to the native sources
  • :module - bundlex project module
  • :app - application that exports project

Link to this section Functions

Link to this function

get(application \\ MixHelper.get_app!())

View Source
get(application :: atom()) ::
  {:ok, t()}
  | {:error,
     :invalid_project_specification
     | {:no_bundlex_project_in_file, path :: binary()}
     | :unknown_application}

Returns the project struct of given application.

If the module has not been loaded yet, it is loaded from project_dir/bundlex.exs file.

Link to this function

native_config_keys()

View Source
native_config_keys() :: [atom()]
Link to this function

project_module?(module)

View Source
project_module?(module()) :: boolean()

Determines if module is a bundlex project module.

Link to this section Callbacks

Callback returning project configuration.