truffle/docs/ModuleMigration.md
Since version 23.1 Truffle uses languages and instruments primarily as Java modules loaded from the Java VM module path. Loading languages and tools from language or tool homes is still supported for compatibility reasons. However, it is deprecated and will be removed in future versions. The motivations for this change are:
For general information on migrating to Java modules, please refer to development-with-jdk-9. The Truffle module is distributed in two versions: open Truffle and closed Truffle. The open Truffle exports all API packages in its module descriptor. On the other hand, the closed Truffle does not export API packages in the module descriptor. Instead, it dynamically exports API packages at runtime to modules that provide the language or instrument, as well as to modules that the language or instrument module reads. While the open Truffle is intended for testing and compile-time purposes, the closed Truffle must be used in production. To correctly load a language or instrument as a module, the following migration steps need to be applied:
org.graalvm.truffle module.provides TruffleLanguageProvider with <LanguageClass>Provider directive.provides TruffleInstrumentProvider with <InstrumentClass>Provider directive.@GenerateLibrary(defaultExportLookupEnabled = true),
the generated implementation of the DefaultExportProvider must be registered in the module descriptor using the provides
directive for the com.oracle.truffle.api.library.provider.DefaultExportProvider service. If you build your language or instrument using mx
the provides directive is generated automatically.@ExportLibrary(useForAOT = true), the generated implementation of the EagerExportProvider
must be registered in the module descriptor using the provides directive for the com.oracle.truffle.api.library.provider.EagerExportProvider
service. If you build your language or instrument using mx the provides directive is generated automatically.com.oracle.truffle.api.library.EagerExportProvider or com.oracle.truffle.api.library.DefaultExportProvider
interface in the module descriptor. They must be replaced by the com.oracle.truffle.api.library.provider.EagerExportProvider and
com.oracle.truffle.api.library.provider.DefaultExportProvider. Providing these deprecated interfaces in the module descriptor
will cause an error during creation of a module layer on the closed Truffle.export <package> to <module>.Here is a sample module descriptor for the simple language.
module org.graalvm.sl {
requires java.base;
requires java.logging;
requires jdk.unsupported;
requires org.antlr.antlr4.runtime;
requires org.graalvm.truffle;
provides com.oracle.truffle.api.provider.TruffleLanguageProvider with
com.oracle.truffle.sl.SLLanguageProvider;
}