title: Build Integration sidebar_position: 2 id: build-integration license: | Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Add to your pom.xml:
<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>3.1.0</version> <executions> <execution> <id>generate-fory-types</id> <phase>generate-sources</phase> <goals> <goal>exec</goal> </goals> <configuration> <executable>foryc</executable> <arguments> <argument>${project.basedir}/src/main/fdl/schema.fdl</argument> <argument>--java_out</argument> <argument>${project.build.directory}/generated-sources/fory</argument> </arguments> </configuration> </execution> </executions> </plugin> </plugins> </build>
Add generated sources:
<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>3.4.0</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>${project.build.directory}/generated-sources/fory</source> </sources> </configuration> </execution> </executions> </plugin> </plugins> </build>
Add to build.gradle:
task generateForyTypes(type: Exec) { commandLine 'foryc', "${projectDir}/src/main/fdl/schema.fdl", '--java_out', "${buildDir}/generated/sources/fory" } compileJava.dependsOn generateForyTypes sourceSets { main { java { srcDir "${buildDir}/generated/sources/fory" } } }
Add to setup.py or pyproject.toml:
# setup.py from setuptools import setup from setuptools.command.build_py import build_py import subprocess class BuildWithForyIdl(build_py): def run(self): subprocess.run([ 'foryc', 'schema.fdl', '--python_out', 'src/generated' ], check=True) super().run() setup( cmdclass={'build_py': BuildWithForyIdl}, # ... )
Add to your Go file:
//go:generate foryc ../schema.fdl --lang go --output . package models
Run:
go generate ./...
Add to build.rs:
use std::process::Command; fn main() { println!("cargo:rerun-if-changed=schema.fdl"); let status = Command::new("foryc") .args(&["schema.fdl", "--rust_out", "src/generated"]) .status() .expect("Failed to run foryc"); if !status.success() { panic!("Fory IDL compilation failed"); } }
Add to CMakeLists.txt:
find_program(FORY_COMPILER foryc) add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/generated/example.h COMMAND ${FORY_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR}/schema.fdl --cpp_out ${CMAKE_CURRENT_SOURCE_DIR}/generated DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/schema.fdl COMMENT "Generating Fory IDL types" ) add_custom_target(generate_fory_idl DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/generated/example.h) add_library(mylib ...) add_dependencies(mylib generate_fory_idl) target_include_directories(mylib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/generated)
Create a rule in BUILD:
genrule( name = "generate_fdl", srcs = ["schema.fdl"], outs = ["generated/example.h"], cmd = "$(location //:fory_compiler) $(SRCS) --cpp_out $(RULEDIR)/generated", tools = ["//:fory_compiler"], ) cc_library( name = "models", hdrs = [":generate_fdl"], # ... )
Add the Fory dependency to pubspec.yaml:
dependencies: fory: ^1.6.1 dev_dependencies: build_runner: ^2.4.0
Generate schema types with the compiler:
foryc schema.fdl --dart_out=lib/generated
Then run build_runner to generate the serializers:
dart run build_runner build