vsg-dev / VulkanSceneGraph

Vulkan & C++17 based Scene Graph Project
http://www.vulkanscenegraph.org
MIT License
1.32k stars 212 forks source link

Integrating Bazel build system #1321

Closed artem-korolev closed 1 week ago

artem-korolev commented 1 week ago

Is your feature request related to a problem? Please describe.
Dear VulkanSceneGraph team, I would like to integrate the Bazel build system into this project. I’m unsure if there’s interest on your end, but if so, I’d be happy to contribute a pull request once the integration is complete. If not, I would appreciate any support to help resolve some of the issues I’m encountering to make the process quicker.

Describe the solution you’d like
The integration is still in its early stages, with a simplified BUILD file that currently lacks several features but should be functional for basic usage. However, the build fails due to an incomplete type error related to vsg::ShaderSet. I’m hoping you might have insights or suggestions on how to resolve this issue, as it may be obvious to someone more familiar with the codebase.

Describe alternatives you’ve considered
I’ve experimented with adjustments to the BUILD file, such as modifying the include paths and dependencies, but none have addressed the incomplete type error. I’ve also reviewed other sections of the code to identify ways to incorporate a full definition for ShaderSet within the Bazel context, though a clear solution remains elusive.

Additional context
Below is my current BUILD file configuration, along with the specific error output from Bazel. The error suggests that ShaderSet is only forward-declared in Options.h, which may be the cause of the incomplete type issue.

Current BUILD file:

load("@rules_cc//cc:defs.bzl", "cc_library")

# Define config_settings for different platforms
config_setting(
    name = "windows",
    values = {"cpu": "x64_windows"},
)

config_setting(
    name = "macos",
    constraint_values = ["@platforms//os:osx"],
    values = {"cpu": "x86_64"},
)

config_setting(
    name = "linux",
    values = {"cpu": "x64_linux"},
)

config_setting(
    name = "android",
    values = {"cpu": "armeabi-v7a"},
)

# Generate the Version.h file
genrule(
    name = "generate_version_header",
    srcs = ["src/vsg/core/Version.h.in"],
    outs = ["include/vsg/core/Version.h"],
    cmd = """
        sed -e 's/@VSG_VERSION_MAJOR@/1/' \
            -e 's/@VSG_VERSION_MINOR@/1/' \
            -e 's/@VSG_VERSION_PATCH@/8/' \
            -e 's/@VSG_SOVERSION@/14/' \
            -e 's/@VSG_MAX_DEVICES@/1/' \
            -e 's/@VSG_MAX_INSTRUMENTATION_LEVEL@/1/' \
            -e 's/@VSG_SUPPORTS_ShaderCompiler@/1/' \
            -e 's/@VSG_SUPPORTS_Windowing@/1/' \
            $< > $@
    """,
    visibility = ["//visibility:public"],
)

# Update the vsg library to depend on the generated header
cc_library(
    name = "vsg",
    srcs = [
        "src/vsg/animation/Animation.cpp",
        "src/vsg/animation/AnimationGroup.cpp",
        "src/vsg/animation/AnimationManager.cpp",
        "src/vsg/animation/CameraAnimation.cpp",
        "src/vsg/animation/FindAnimations.cpp",
        "src/vsg/animation/Joint.cpp",
        "src/vsg/animation/JointSampler.cpp",
        "src/vsg/animation/MorphSampler.cpp",
        "src/vsg/animation/TransformSampler.cpp",
        "src/vsg/app/Camera.cpp",
        "src/vsg/app/CommandGraph.cpp",
        "src/vsg/app/CompileManager.cpp",
        "src/vsg/app/CompileTraversal.cpp",
        "src/vsg/app/EllipsoidModel.cpp",
        "src/vsg/app/Presentation.cpp",
        "src/vsg/app/ProjectionMatrix.cpp",
        "src/vsg/app/RecordAndSubmitTask.cpp",
        "src/vsg/app/RecordTraversal.cpp",
        "src/vsg/app/RenderGraph.cpp",
        "src/vsg/app/SecondaryCommandGraph.cpp",
        "src/vsg/app/Trackball.cpp",
        "src/vsg/app/TransferTask.cpp",
        "src/vsg/app/UpdateOperations.cpp",
        "src/vsg/app/View.cpp",
        "src/vsg/app/ViewMatrix.cpp",
        "src/vsg/app/Viewer.cpp",
        "src/vsg/app/Window.cpp",
        "src/vsg/app/WindowAdapter.cpp",
        "src/vsg/app/WindowResizeHandler.cpp",
        "src/vsg/app/WindowTraits.cpp",
        "src/vsg/commands/BeginQuery.cpp",
        "src/vsg/commands/BindIndexBuffer.cpp",
        "src/vsg/commands/BindVertexBuffers.cpp",
        "src/vsg/commands/BlitImage.cpp",
        "src/vsg/commands/ClearAttachments.cpp",
        "src/vsg/commands/ClearImage.cpp",
        "src/vsg/commands/Commands.cpp",
        "src/vsg/commands/CopyAndReleaseBuffer.cpp",
        "src/vsg/commands/CopyAndReleaseImage.cpp",
        "src/vsg/commands/CopyImage.cpp",
        "src/vsg/commands/CopyImageToBuffer.cpp",
        "src/vsg/commands/CopyImageViewToWindow.cpp",
        "src/vsg/commands/CopyQueryPoolResults.cpp",
        "src/vsg/commands/Dispatch.cpp",
        "src/vsg/commands/Draw.cpp",
        "src/vsg/commands/DrawIndexed.cpp",
        "src/vsg/commands/DrawIndexedIndirect.cpp",
        "src/vsg/commands/DrawIndirect.cpp",
        "src/vsg/commands/EndQuery.cpp",
        "src/vsg/commands/Event.cpp",
        "src/vsg/commands/ExecuteCommands.cpp",
        "src/vsg/commands/NextSubPass.cpp",
        "src/vsg/commands/PipelineBarrier.cpp",
        "src/vsg/commands/ResetQueryPool.cpp",
        "src/vsg/commands/ResolveImage.cpp",
        "src/vsg/commands/SetDepthBias.cpp",
        "src/vsg/commands/SetLineWidth.cpp",
        "src/vsg/commands/SetPrimitiveTopology.cpp",
        "src/vsg/commands/SetScissor.cpp",
        "src/vsg/commands/SetViewport.cpp",
        "src/vsg/commands/WriteTimestamp.cpp",
        "src/vsg/core/Allocator.cpp",
        "src/vsg/core/Auxiliary.cpp",
        "src/vsg/core/ConstVisitor.cpp",
        "src/vsg/core/Data.cpp",
        "src/vsg/core/External.cpp",
        "src/vsg/core/IntrusiveAllocator.cpp",
        "src/vsg/core/MemorySlots.cpp",
        "src/vsg/core/Object.cpp",
        "src/vsg/core/Objects.cpp",
        "src/vsg/core/Version.cpp",
        "src/vsg/core/Visitor.cpp",
        "src/vsg/io/AsciiInput.cpp",
        "src/vsg/io/AsciiOutput.cpp",
        "src/vsg/io/BinaryInput.cpp",
        "src/vsg/io/BinaryOutput.cpp",
        "src/vsg/io/DatabasePager.cpp",
        "src/vsg/io/FileSystem.cpp",
        "src/vsg/io/Input.cpp",
        "src/vsg/io/Logger.cpp",
        "src/vsg/io/ObjectFactory.cpp",
        "src/vsg/io/Options.cpp",
        "src/vsg/io/Output.cpp",
        "src/vsg/io/Path.cpp",
        "src/vsg/io/ReaderWriter.cpp",
        "src/vsg/io/VSG.cpp",
        "src/vsg/io/convert_utf.cpp",
        "src/vsg/io/glsl.cpp",
        "src/vsg/io/mem_stream.cpp",
        "src/vsg/io/read.cpp",
        "src/vsg/io/spirv.cpp",
        "src/vsg/io/tile.cpp",
        "src/vsg/io/txt.cpp",
        "src/vsg/io/write.cpp",
        "src/vsg/lighting/AmbientLight.cpp",
        "src/vsg/lighting/DirectionalLight.cpp",
        "src/vsg/lighting/HardShadows.cpp",
        "src/vsg/lighting/Light.cpp",
        "src/vsg/lighting/PercentageCloserSoftShadows.cpp",
        "src/vsg/lighting/PointLight.cpp",
        "src/vsg/lighting/ShadowSettings.cpp",
        "src/vsg/lighting/SoftShadows.cpp",
        "src/vsg/lighting/SpotLight.cpp",
        "src/vsg/maths/maths_transform.cpp",
        "src/vsg/meshshaders/DrawMeshTasks.cpp",
        "src/vsg/meshshaders/DrawMeshTasksIndirect.cpp",
        "src/vsg/meshshaders/DrawMeshTasksIndirectCount.cpp",
        "src/vsg/nodes/AbsoluteTransform.cpp",
        "src/vsg/nodes/Bin.cpp",
        "src/vsg/nodes/CullGroup.cpp",
        "src/vsg/nodes/CullNode.cpp",
        "src/vsg/nodes/DepthSorted.cpp",
        "src/vsg/nodes/Geometry.cpp",
        "src/vsg/nodes/Group.cpp",
        "src/vsg/nodes/InstrumentationNode.cpp",
        "src/vsg/nodes/LOD.cpp",
        "src/vsg/nodes/Layer.cpp",
        "src/vsg/nodes/MatrixTransform.cpp",
        "src/vsg/nodes/Node.cpp",
        "src/vsg/nodes/PagedLOD.cpp",
        "src/vsg/nodes/QuadGroup.cpp",
        "src/vsg/nodes/RegionOfInterest.cpp",
        "src/vsg/nodes/StateGroup.cpp",
        "src/vsg/nodes/Switch.cpp",
        "src/vsg/nodes/TileDatabase.cpp",
        "src/vsg/nodes/Transform.cpp",
        "src/vsg/nodes/VertexDraw.cpp",
        "src/vsg/nodes/VertexIndexDraw.cpp",
        "src/vsg/raytracing/AccelerationGeometry.cpp",
        "src/vsg/raytracing/AccelerationStructure.cpp",
        "src/vsg/raytracing/BottomLevelAccelerationStructure.cpp",
        "src/vsg/raytracing/BuildAccelerationStructureTraversal.cpp",
        "src/vsg/raytracing/DescriptorAccelerationStructure.cpp",
        "src/vsg/raytracing/RayTracingPipeline.cpp",
        "src/vsg/raytracing/RayTracingShaderGroup.cpp",
        "src/vsg/raytracing/TopLevelAccelerationStructure.cpp",
        "src/vsg/raytracing/TraceRays.cpp",
        "src/vsg/state/ArrayState.cpp",
        "src/vsg/state/BindDescriptorSet.cpp",
        "src/vsg/state/Buffer.cpp",
        "src/vsg/state/BufferInfo.cpp",
        "src/vsg/state/BufferView.cpp",
        "src/vsg/state/ColorBlendState.cpp",
        "src/vsg/state/ComputePipeline.cpp",
        "src/vsg/state/DepthStencilState.cpp",
        "src/vsg/state/Descriptor.cpp",
        "src/vsg/state/DescriptorBuffer.cpp",
        "src/vsg/state/DescriptorImage.cpp",
        "src/vsg/state/DescriptorSet.cpp",
        "src/vsg/state/DescriptorSetLayout.cpp",
        "src/vsg/state/DescriptorTexelBufferView.cpp",
        "src/vsg/state/DynamicState.cpp",
        "src/vsg/state/GraphicsPipeline.cpp",
        "src/vsg/state/Image.cpp",
        "src/vsg/state/ImageInfo.cpp",
        "src/vsg/state/ImageView.cpp",
        "src/vsg/state/InputAssemblyState.cpp",
        "src/vsg/state/MultisampleState.cpp",
        "src/vsg/state/PipelineLayout.cpp",
        "src/vsg/state/PushConstants.cpp",
        "src/vsg/state/QueryPool.cpp",
        "src/vsg/state/RasterizationState.cpp",
        "src/vsg/state/ResourceHints.cpp",
        "src/vsg/state/Sampler.cpp",
        "src/vsg/state/ShaderModule.cpp",
        "src/vsg/state/ShaderStage.cpp",
        "src/vsg/state/StateCommand.cpp",
        "src/vsg/state/StateSwitch.cpp",
        "src/vsg/state/TessellationState.cpp",
        "src/vsg/state/VertexInputState.cpp",
        "src/vsg/state/ViewDependentState.cpp",
        "src/vsg/state/ViewportState.cpp",
        "src/vsg/text/CpuLayoutTechnique.cpp",
        "src/vsg/text/Font.cpp",
        "src/vsg/text/GpuLayoutTechnique.cpp",
        "src/vsg/text/StandardLayout.cpp",
        "src/vsg/text/Text.cpp",
        "src/vsg/text/TextGroup.cpp",
        "src/vsg/text/shaders/text_ShaderSet.cpp",
        "src/vsg/threading/Affinity.cpp",
        "src/vsg/threading/DeleteQueue.cpp",
        "src/vsg/threading/OperationThreads.cpp",
        "src/vsg/ui/ApplicationEvent.cpp",
        "src/vsg/ui/CollectEvents.cpp",
        "src/vsg/ui/KeyEvent.cpp",
        "src/vsg/ui/Keyboard.cpp",
        "src/vsg/ui/PlayEvents.cpp",
        "src/vsg/ui/PointerEvent.cpp",
        "src/vsg/ui/PrintEvents.cpp",
        "src/vsg/ui/RecordEvents.cpp",
        "src/vsg/ui/ScrollWheelEvent.cpp",
        "src/vsg/ui/ShiftEventTime.cpp",
        "src/vsg/ui/TouchEvent.cpp",
        "src/vsg/ui/UIEvent.cpp",
        "src/vsg/ui/WindowEvent.cpp",
        "src/vsg/utils/Builder.cpp",
        "src/vsg/utils/CommandLine.cpp",
        "src/vsg/utils/ComputeBounds.cpp",
        "src/vsg/utils/FindDynamicObjects.cpp",
        "src/vsg/utils/GpuAnnotation.cpp",
        "src/vsg/utils/GraphicsPipelineConfigurator.cpp",
        "src/vsg/utils/Instrumentation.cpp",
        "src/vsg/utils/Intersector.cpp",
        "src/vsg/utils/LineSegmentIntersector.cpp",
        "src/vsg/utils/LoadPagedLOD.cpp",
        "src/vsg/utils/PolytopeIntersector.cpp",
        "src/vsg/utils/Profiler.cpp",
        "src/vsg/utils/PropagateDynamicObjects.cpp",
        "src/vsg/utils/ShaderCompiler.cpp",
        "src/vsg/utils/ShaderSet.cpp",
        "src/vsg/utils/SharedObjects.cpp",
        "src/vsg/utils/shaders/flat_ShaderSet.cpp",
        "src/vsg/utils/shaders/pbr_ShaderSet.cpp",
        "src/vsg/utils/shaders/phong_ShaderSet.cpp",
        "src/vsg/vk/CommandBuffer.cpp",
        "src/vsg/vk/CommandPool.cpp",
        "src/vsg/vk/Context.cpp",
        "src/vsg/vk/DescriptorPool.cpp",
        "src/vsg/vk/DescriptorPools.cpp",
        "src/vsg/vk/Device.cpp",
        "src/vsg/vk/DeviceExtensions.cpp",
        "src/vsg/vk/DeviceFeatures.cpp",
        "src/vsg/vk/DeviceMemory.cpp",
        "src/vsg/vk/Fence.cpp",
        "src/vsg/vk/Framebuffer.cpp",
        "src/vsg/vk/Instance.cpp",
        "src/vsg/vk/InstanceExtensions.cpp",
        "src/vsg/vk/MemoryBufferPools.cpp",
        "src/vsg/vk/PhysicalDevice.cpp",
        "src/vsg/vk/Queue.cpp",
        "src/vsg/vk/RenderPass.cpp",
        "src/vsg/vk/ResourceRequirements.cpp",
        "src/vsg/vk/Semaphore.cpp",
        "src/vsg/vk/Surface.cpp",
        "src/vsg/vk/Swapchain.cpp",
    ] + select({
        ":android": ["src/vsg/platform/android/Android_Window.cpp"],
        ":macos": ["src/vsg/platform/macos/MacOS_Window.mm"],
        ":windows": ["src/vsg/platform/win32/Win32_Window.cpp"],
        "//conditions:default": ["src/vsg/platform/xcb/Xcb_Window.cpp"],
    }),
    hdrs = glob([
        "include/vsg/**/*.h",
    ]) + ["include/vsg/core/Version.h"],
    copts = [
        "-std=c++17",
    ] + select({
        ":macos": [
            "-x",
            "objective-c++",
        ],
        "//conditions:default": [],
    }),
    includes = [
        "./include",
        "./src",
        "./src/vsg/text",
        "./src/vsg/utils"
    ],
    linkopts = select({
        ":android": ["-landroid"],
        ":macos": [
            "-framework",
            "Cocoa",
            "-framework",
            "QuartzCore",
        ],
        "//conditions:default": [],
    }),
    visibility = ["//visibility:public"],
    deps = [
        ":generate_version_header",  # Add the dependency on the generated header
        # ":threads",
        # ":vulkan",
    ] + select({
        ":android": [],
        ":macos": [],
        ":windows": [],
        "//conditions:default": [],
        # "//conditions:default": [":xcb"],
    }),
)

Error output:

$ bazel build //:vsg
INFO: Analyzed target //:vsg (1 packages loaded, 532 targets configured).
In file included from src/vsg/text/shaders/text_ShaderSet.cpp:1:
In file included from include/vsg/io/VSG.h:15:
include/vsg/io/ReaderWriter.h:61:36: error: 'vsg::ShaderSet' is an incomplete type
   61 |             return vsg::ref_ptr<T>(dynamic_cast<T*>(object.get()));
      |                                    ^           ~~~~
src/vsg/text/shaders/text_ShaderSet.cpp:1094:11: note: in instantiation of function template specialization 'vsg::ReaderWriter::read_cast<vsg::ShaderSet>' requested here
 1094 | return io.read_cast<vsg::ShaderSet>(data, sizeof(data));
      |           ^
include/vsg/io/Options.h:29:11: note: forward declaration of 'vsg::ShaderSet'
   29 |     class ShaderSet;
      |           ^
In file included from src/vsg/text/shaders/text_ShaderSet.cpp:1:
In file included from include/vsg/io/VSG.h:15:
In file included from include/vsg/io/ReaderWriter.h:15:
In file included from include/vsg/core/Inherit.h:15:
In file included from include/vsg/app/RecordTraversal.h:16:
In file included from include/vsg/core/Object.h:22:
include/vsg/core/ref_ptr.h:69:27: error: member access into incomplete type 'vsg::ShaderSet'
   69 |             if (_ptr) _ptr->unref();
      |                           ^
src/vsg/text/shaders/text_ShaderSet.cpp:1094:11: note: in instantiation of member function 'vsg::ref_ptr<vsg::ShaderSet>::~ref_ptr' requested here
 1094 | return io.read_cast<vsg::ShaderSet>(data, sizeof(data));
      |           ^
include/vsg/io/Options.h:29:11: note: forward declaration of 'vsg::ShaderSet'
   29 |     class ShaderSet;
      |           ^
2 errors generated.
Target //:vsg failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 3.630s, Critical Path: 3.45s
INFO: 16 processes: 14 internal, 2 processwrapper-sandbox.
ERROR: Build did NOT complete successfully

I am using LLVM 17.0.6 for this build process. Any guidance on resolving this error or further integrating Bazel would be greatly appreciated.

robertosfield commented 1 week ago

It make zero sense for us to support multiple "build a build systems" systems. Which is what you are asking for.

We have CMake support, it can build on all the platforms that users require the VSG to be built upon. It's a single "build a build system" to covers all bases.

Adding another parallel "build a build system" to this would just add more maintenance burden for no extra benefit. We would see build more errors when one of the "build a build systems" gets out of sync with the code base or platform requirements.

I know this is serious issue as I went through the serious pain of trying to manage multiple build systems in the first decade of the OpenSceneGraph project before CMake came along and solved the cross platform build issue. Trying to manage multiple alternate build systems is NIGHTMARE, it's a horrible waste of mind space and developer time.

CMake might not be your preferred build system, but it's what the VSG uses, and what all the major dependencies use. Please just learn how to use CMake, install the libs and headers and link your application to as everyone else does.