Skip to content

Public API for rules_fortran.

fortran_binary

fortran_binary(name, deps, srcs, hdrs, copts, defines, includes, linkopts)

Compiles and links Fortran sources into an executable.

This rule compiles Fortran source files and links them with dependencies into an executable binary.

Example: fortran_binary( name = "myapp", srcs = ["main.f90"], deps = [":mylib"], linkopts = ["-llapack"], )

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsList of fortran_library or cc_library targets to link against.List of labelsoptional[]
srcsList of Fortran source files to compile.List of labelsoptional[]
hdrsHeader/include files (.inc, .mod) for INCLUDE statements and pre-built modules.List of labelsoptional[]
coptsAdditional compiler options.List of stringsoptional[]
definesPreprocessor defines for .F files (e.g., ['_OPENMP', 'USE_MPI']).List of stringsoptional[]
includesList of include directories to add to the compile line.List of stringsoptional[]
linkoptsAdditional linker options.List of stringsoptional[]

fortran_library

fortran_library(name, deps, srcs, hdrs, copts, defines, includes, linkopts)

Compiles Fortran sources into a static library.

Examples: fortran_library( name = "math", srcs = ["module.f90", "utils.f90"], )

fortran_library(
    name = "advanced",
    srcs = ["solver.f90"],
    deps = [":math"],
    copts = ["-O2"],
)

fortran_library(
    name = "all",
    deps = [":math", ":advanced"],
)

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsList of fortran_library or cc_library targets that this library depends on.List of labelsoptional[]
srcsList of Fortran source files to compile.List of labelsoptional[]
hdrsHeader/include files (.inc, .mod) for INCLUDE statements and pre-built modules.List of labelsoptional[]
coptsAdditional compiler options to pass to the Fortran compiler.List of stringsoptional[]
definesPreprocessor defines for .F files (e.g., ['_OPENMP', 'USE_MPI']).List of stringsoptional[]
includesList of include directories to add to the compile line.List of stringsoptional[]
linkoptsAdditional linker options (propagated to binaries).List of stringsoptional[]

fortran_test

fortran_test(name, deps, srcs, hdrs, copts, defines, includes, linkopts)

Compiles and links Fortran sources into a test executable.

This rule is similar to fortran_binary but is used for test targets. The resulting executable will be run as part of bazel test.

Example: fortran_test( name = "mytest", srcs = ["test.f90"], deps = [":mylib"], )

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsList of fortran_library or cc_library targets to link against.List of labelsoptional[]
srcsList of Fortran test source files.List of labelsoptional[]
hdrsHeader/include files (.inc, .mod) for INCLUDE statements and pre-built modules.List of labelsoptional[]
coptsAdditional compiler options.List of stringsoptional[]
definesPreprocessor defines for .F files (e.g., ['_OPENMP', 'USE_MPI']).List of stringsoptional[]
includesList of include directories to add to the compile line.List of stringsoptional[]
linkoptsAdditional linker options.List of stringsoptional[]

FortranInfo

FortranInfo(transitive_sources, transitive_modules, transitive_objects, transitive_libraries,
            module_map, compile_flags, link_flags)

Provider for Fortran compilation information.

This provider is used to propagate information about compiled Fortran code, including module files, object files, and transitive dependencies.

FIELDS

NameDescription
transitive_sourcesdepset of source files (for building)
transitive_modulesdepset of module files (.mod)
transitive_objectsdepset of object files (.o)
transitive_librariesdepset of static library files (.a)
module_mapdict mapping module names to module files
compile_flagslist of compilation flags
link_flagslist of link flags