libflux

package
v0.173.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2022 License: MIT Imports: 13 Imported by: 4

README

CGO Build Details

This package is a wrapper interface for the flux library.

The flux library is written in Rust and exposes a C ABI (Application Binary Interface). The ABI is exposed to Go using a C header file. The path to this header file is intended to be influxdata/flux.h.

Build and link flags are supplied to cgo from either link_dynamic.go or link_static.go. This can be toggled using the static_build tag when building with Go. If static_build is used, the --static option will be passed to pkg-config and completely static linking will be used. The default for both cgo and flux it to use dynamic linking.

No other cgo directives should be used. If additional ones are needed, changes should be made to pkg-config. Directives to cgo located in one file are global to the package so they should not be specified multiple multiple times in different files. The behavior of cgo when this is done is to repeat the directive multiple times.

Any other file that interacts with the C library can do so using import "C".

// include "influxdata/flux.h"
// include <stdlib.h>
import "C"

When referencing header files, the general order is:

  • Library headers
  • Standard headers

This order is to ensure that there are no implicit dependencies in library headers. The default C behavior for header files concatenates all of the included files together. If the standard headers are placed before library headers, the library headers can forget to include a standard header and a compiler error won't happen because the file that included the library header happened to accidentally fix the problem. To avoid accidentally fixing a problem and getting a rude compiler error when the header file order is changed, library headers should be included before standard headers to reduce this possibility.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnvStdlib

func EnvStdlib() []byte

EnvStdlib takes care of creating a flux_buffer_t, passes the buffer to the Flatbuffers TypeEnvironment and then takes care of freeing the data

func FindVarType added in v0.74.0

func FindVarType(astPkg *ASTPkg, varName string) (semantic.MonoType, error)

func MergePackages

func MergePackages(outPkg *ASTPkg, inPkg *ASTPkg) error

Merge packages merges the files of a given input package into a given output package. This function borrows the input and output packages, but does not own them. Memory must still be freed by the caller of this function.

func SemanticPackages added in v0.166.0

func SemanticPackages() (map[string]*semantic.Package, error)

Types

type ASTPkg

type ASTPkg struct {
	// contains filtered or unexported fields
}

ASTPkg is a parsed AST.

func Parse

func Parse(fname string, src string) *ASTPkg

Parse will take a filename and source string and return a parsed source file.

func ParseJSON

func ParseJSON(bs []byte) (*ASTPkg, error)

ParseJSON will take an AST formatted as JSON and return a handle the Rust AST package.

func ParseString

func ParseString(src string) *ASTPkg

func (ASTPkg) ASTHandle

func (p ASTPkg) ASTHandle()

ASTHandle makes sure that this type implements the flux.ASTHandle interface.

func (ASTPkg) Format added in v0.109.0

func (p ASTPkg) Format() (string, error)

func (*ASTPkg) Free

func (p *ASTPkg) Free()

func (ASTPkg) GetError

func (p ASTPkg) GetError() error

GetError will return the first error in the AST, if any

func (*ASTPkg) MarshalJSON

func (p *ASTPkg) MarshalJSON() ([]byte, error)

func (*ASTPkg) String

func (p *ASTPkg) String() string

type Analyzer

type Analyzer struct {
	// contains filtered or unexported fields
}

func NewAnalyzer

func NewAnalyzer() *Analyzer

func NewAnalyzerWithOptions added in v0.164.0

func NewAnalyzerWithOptions(options Options) (*Analyzer, error)

func (*Analyzer) Analyze

func (p *Analyzer) Analyze(src string, astPkg *ASTPkg) (*SemanticPkg, *FluxError)

func (*Analyzer) AnalyzeString added in v0.148.0

func (p *Analyzer) AnalyzeString(src string) (*SemanticPkg, *FluxError)

func (*Analyzer) Free

func (p *Analyzer) Free()

Free frees the memory allocated by Rust for the semantic graph.

type FluxError added in v0.148.0

type FluxError struct {
	// contains filtered or unexported fields
}

func (*FluxError) Free added in v0.148.0

func (p *FluxError) Free()

func (*FluxError) GoError added in v0.148.0

func (p *FluxError) GoError() error

func (*FluxError) Print added in v0.148.0

func (p *FluxError) Print()

type Options added in v0.164.0

type Options struct {
	Features []string `json:"features,omitempty"`
}

func NewOptions added in v0.164.0

func NewOptions(ctx context.Context) Options

type SemanticPkg

type SemanticPkg struct {
	// contains filtered or unexported fields
}

SemanticPkg is a Rust pointer to a semantic package.

func Analyze

func Analyze(astPkg *ASTPkg) (*SemanticPkg, error)

Analyze parses the given Flux source, performs type inference (taking into account types from prelude and stdlib) and returns an a SemanticPkg containing an opaque pointer to the semantic graph. The graph can be deserialized by calling MarshalFB.

Note that Analyze will consume the AST, so astPkg.ptr will be set to nil, even if there's an error in analysis.

func AnalyzeWithOptions added in v0.164.0

func AnalyzeWithOptions(astPkg *ASTPkg, options Options) (*SemanticPkg, error)

func (*SemanticPkg) Free

func (p *SemanticPkg) Free()

Free frees the memory allocated by Rust for the semantic graph.

func (*SemanticPkg) MarshalFB

func (p *SemanticPkg) MarshalFB() ([]byte, error)

MarshalFB serializes the given semantic package into a flatbuffer.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL