Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SPIRV_TOOLS_EXPORT to public C++ API #5591

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/spirv-tools/libspirv.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ extern "C" {
#else
#define SPIRV_TOOLS_EXPORT __declspec(dllimport)
#endif
#define SPIRV_TOOLS_LOCAL
#else
#if defined(SPIRV_TOOLS_IMPLEMENTATION)
#define SPIRV_TOOLS_EXPORT __attribute__((visibility("default")))
#define SPIRV_TOOLS_LOCAL __attribute__((visibility("hidden")))
#else
#define SPIRV_TOOLS_EXPORT
#define SPIRV_TOOLS_LOCAL
#endif
#endif
#else
#define SPIRV_TOOLS_EXPORT
#define SPIRV_TOOLS_LOCAL
#endif

// Helpers
Expand Down
15 changes: 8 additions & 7 deletions include/spirv-tools/libspirv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using InstructionParser =
std::function<spv_result_t(const spv_parsed_instruction_t& instruction)>;

// C++ RAII wrapper around the C context object spv_context.
class Context {
class SPIRV_TOOLS_EXPORT Context {
public:
// Constructs a context targeting the given environment |env|.
//
Expand Down Expand Up @@ -73,7 +73,7 @@ class Context {
};

// A RAII wrapper around a validator options object.
class ValidatorOptions {
class SPIRV_TOOLS_EXPORT ValidatorOptions {
public:
ValidatorOptions() : options_(spvValidatorOptionsCreate()) {}
~ValidatorOptions() { spvValidatorOptionsDestroy(options_); }
Expand Down Expand Up @@ -163,7 +163,7 @@ class ValidatorOptions {
};

// A C++ wrapper around an optimization options object.
class OptimizerOptions {
class SPIRV_TOOLS_EXPORT OptimizerOptions {
public:
OptimizerOptions() : options_(spvOptimizerOptionsCreate()) {}
~OptimizerOptions() { spvOptimizerOptionsDestroy(options_); }
Expand Down Expand Up @@ -205,7 +205,7 @@ class OptimizerOptions {
};

// A C++ wrapper around a reducer options object.
class ReducerOptions {
class SPIRV_TOOLS_EXPORT ReducerOptions {
public:
ReducerOptions() : options_(spvReducerOptionsCreate()) {}
~ReducerOptions() { spvReducerOptionsDestroy(options_); }
Expand Down Expand Up @@ -236,7 +236,7 @@ class ReducerOptions {
};

// A C++ wrapper around a fuzzer options object.
class FuzzerOptions {
class SPIRV_TOOLS_EXPORT FuzzerOptions {
public:
FuzzerOptions() : options_(spvFuzzerOptionsCreate()) {}
~FuzzerOptions() { spvFuzzerOptionsDestroy(options_); }
Expand Down Expand Up @@ -283,7 +283,7 @@ class FuzzerOptions {
// provides methods for assembling, disassembling, and validating.
//
// Instances of this class provide basic thread-safety guarantee.
class SpirvTools {
class SPIRV_TOOLS_EXPORT SpirvTools {
public:
enum {
// Default assembling option used by assemble():
Expand Down Expand Up @@ -388,7 +388,8 @@ class SpirvTools {
bool IsValid() const;

private:
struct Impl; // Opaque struct for holding the data fields used by this class.
struct SPIRV_TOOLS_LOCAL
Impl; // Opaque struct for holding the data fields used by this class.
std::unique_ptr<Impl> impl_; // Unique pointer to implementation data.
};

Expand Down
19 changes: 10 additions & 9 deletions include/spirv-tools/linker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace spvtools {

class LinkerOptions {
class SPIRV_TOOLS_EXPORT LinkerOptions {
public:
// Returns whether a library or an executable should be produced by the
// linking phase.
Expand Down Expand Up @@ -84,14 +84,15 @@ class LinkerOptions {
// * Some entry points were defined multiple times;
// * Some imported symbols did not have an exported counterpart;
// * Possibly other reasons.
spv_result_t Link(const Context& context,
const std::vector<std::vector<uint32_t>>& binaries,
std::vector<uint32_t>* linked_binary,
const LinkerOptions& options = LinkerOptions());
spv_result_t Link(const Context& context, const uint32_t* const* binaries,
const size_t* binary_sizes, size_t num_binaries,
std::vector<uint32_t>* linked_binary,
const LinkerOptions& options = LinkerOptions());
SPIRV_TOOLS_EXPORT spv_result_t
Link(const Context& context, const std::vector<std::vector<uint32_t>>& binaries,
std::vector<uint32_t>* linked_binary,
const LinkerOptions& options = LinkerOptions());
SPIRV_TOOLS_EXPORT spv_result_t
Link(const Context& context, const uint32_t* const* binaries,
const size_t* binary_sizes, size_t num_binaries,
std::vector<uint32_t>* linked_binary,
const LinkerOptions& options = LinkerOptions());

} // namespace spvtools

Expand Down
4 changes: 2 additions & 2 deletions include/spirv-tools/linter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace spvtools {
// provides a method for linting.
//
// Instances of this class provides basic thread-safety guarantee.
class Linter {
class SPIRV_TOOLS_EXPORT Linter {
public:
explicit Linter(spv_target_env env);

Expand All @@ -40,7 +40,7 @@ class Linter {
bool Run(const uint32_t* binary, size_t binary_size);

private:
struct Impl;
struct SPIRV_TOOLS_LOCAL Impl;
std::unique_ptr<Impl> impl_;
};
} // namespace spvtools
Expand Down
6 changes: 3 additions & 3 deletions include/spirv-tools/optimizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ struct DescriptorSetAndBinding;
// provides methods for registering optimization passes and optimizing.
//
// Instances of this class provides basic thread-safety guarantee.
class Optimizer {
class SPIRV_TOOLS_EXPORT Optimizer {
public:
// The token for an optimization pass. It is returned via one of the
// Create*Pass() standalone functions at the end of this header file and
// consumed by the RegisterPass() method. Tokens are one-time objects that
// only support move; copying is not allowed.
struct PassToken {
struct Impl; // Opaque struct for holding internal data.
struct SPIRV_TOOLS_LOCAL Impl; // Opaque struct for holding internal data.

PassToken(std::unique_ptr<Impl>);

Expand Down Expand Up @@ -239,7 +239,7 @@ class Optimizer {
Optimizer& SetValidateAfterAll(bool validate);

private:
struct Impl; // Opaque struct for holding internal data.
struct SPIRV_TOOLS_LOCAL Impl; // Opaque struct for holding internal data.
std::unique_ptr<Impl> impl_; // Unique pointer to internal data.
};

Expand Down