[Compiler][API] Bind plugin activation options (#25226) Embedded sessions have a private option binder, but plugin activation options were registered only with the global command line. Expose them through the session binder so C and Python API callers can select plugins without initializing global CLI state, while library loading remains a separate initialization step. Assisted-by: Codex Signed-off-by: Christopher McGirr <mcgirr@roofline.ai>
diff --git a/compiler/src/iree/compiler/API/Internal/CompilerDriver.cpp b/compiler/src/iree/compiler/API/Internal/CompilerDriver.cpp index b0bdb79..4a2d25e 100644 --- a/compiler/src/iree/compiler/API/Internal/CompilerDriver.cpp +++ b/compiler/src/iree/compiler/API/Internal/CompilerDriver.cpp
@@ -616,6 +616,7 @@ // Register each options struct with the binder so we can manipulate // mnemonically via the API. + pluginManagerOptions.bindOptions(binder); pipelineOptions.bindOptions(binder); bindingOptions.bindOptions(binder); preprocessingOptions.bindOptions(binder);
diff --git a/compiler/src/iree/compiler/API/test/BUILD.bazel b/compiler/src/iree/compiler/API/test/BUILD.bazel index 0504dda..c417f0d 100644 --- a/compiler/src/iree/compiler/API/test/BUILD.bazel +++ b/compiler/src/iree/compiler/API/test/BUILD.bazel
@@ -33,3 +33,15 @@ "@com_google_googletest//:gtest", ], ) + +iree_compiler_cc_test( + name = "plugin-flags-test", + testonly = True, + srcs = ["plugin_flags_test.cc"], + deps = [ + "//compiler/bindings/c:headers", + "//compiler/src/iree/compiler/API:Impl", + "//compiler/src/iree/testing:gtest_main", + "@com_google_googletest//:gtest", + ], +)
diff --git a/compiler/src/iree/compiler/API/test/CMakeLists.txt b/compiler/src/iree/compiler/API/test/CMakeLists.txt index 611ae75..786631e 100644 --- a/compiler/src/iree/compiler/API/test/CMakeLists.txt +++ b/compiler/src/iree/compiler/API/test/CMakeLists.txt
@@ -34,6 +34,19 @@ iree::testing::gtest_main ) +iree_cc_test( + NAME + plugin-flags-test + SRCS + "plugin_flags_test.cc" + DEPS + gmock + gtest + iree::compiler::API::Impl + iree::compiler::bindings::c::headers + iree::testing::gtest_main +) + ### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ### # Move to bin/ directory and systematically name more appropriately.
diff --git a/compiler/src/iree/compiler/API/test/plugin_flags_test.cc b/compiler/src/iree/compiler/API/test/plugin_flags_test.cc new file mode 100644 index 0000000..8ac31d2 --- /dev/null +++ b/compiler/src/iree/compiler/API/test/plugin_flags_test.cc
@@ -0,0 +1,60 @@ +// Copyright 2026 The IREE Authors +// +// Licensed under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +// C API tests for the plugin activation flags that must be reachable through +// the embedding API. Loading a library is a global step that precedes +// initialization, so it stays out of the session flags. + +#include <gtest/gtest.h> + +#include <string> + +#include "iree/compiler/embedding_api.h" + +namespace { + +class PluginFlagsCAPITest : public ::testing::Test { +protected: + static void SetUpTestSuite() { ireeCompilerGlobalInitialize(); } + static void TearDownTestSuite() { ireeCompilerGlobalShutdown(); } + + void SetUp() override { session = ireeCompilerSessionCreate(); } + void TearDown() override { ireeCompilerSessionDestroy(session); } + + std::string getFlags() { + std::string flags; + ireeCompilerSessionGetFlags( + session, /*nonDefaultOnly=*/false, + [](const char *flag, size_t length, void *userData) { + auto *flags = static_cast<std::string *>(userData); + flags->append(flag, length); + flags->push_back('\n'); + }, + &flags); + return flags; + } + + iree_compiler_session_t *session = nullptr; +}; + +TEST_F(PluginFlagsCAPITest, ActivationFlagsAccepted) { + const char *flags[] = {"--iree-plugin=-example", "--iree-print-plugin-info"}; + iree_compiler_error_t *err = ireeCompilerSessionSetFlags(session, 2, flags); + ASSERT_EQ(err, nullptr) << ireeCompilerErrorGetMessage(err); + std::string actual = getFlags(); + EXPECT_NE(actual.find("--iree-plugin=-example"), std::string::npos) << actual; + EXPECT_NE(actual.find("--iree-print-plugin-info"), std::string::npos) + << actual; +} + +TEST_F(PluginFlagsCAPITest, LoadFlagRejected) { + const char *flag = "--iree-load-plugin=/does/not/exist"; + iree_compiler_error_t *err = ireeCompilerSessionSetFlags(session, 1, &flag); + ASSERT_NE(err, nullptr) << "library loading is not a session option"; + ireeCompilerErrorDestroy(err); +} + +} // namespace