Skip to content

Commit 0203976

Browse files
authored
Merge pull request KhronosGroup#2277 from ben-clayton/build-info
Generate build information from CHANGES.md
2 parents 5aaa0c2 + fbe9a23 commit 0203976

File tree

16 files changed

+515
-64
lines changed

16 files changed

+515
-64
lines changed

Android.mk

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@
3333

3434
LOCAL_PATH := $(call my-dir)
3535

36+
# Generate glslang/build_info.h
37+
GLSLANG_GENERATED_INCLUDEDIR:=$(TARGET_OUT)/include
38+
GLSLANG_BUILD_INFO_H:=$(GLSLANG_GENERATED_INCLUDEDIR)/glslang/build_info.h
39+
40+
define gen_glslang_build_info_h
41+
$(call generate-file-dir,$(GLSLANG_GENERATED_INCLUDEDIR)/dummy_filename)
42+
$(GLSLANG_BUILD_INFO_H): \
43+
$(LOCAL_PATH)/build_info.py \
44+
$(LOCAL_PATH)/build_info.h.tmpl \
45+
$(LOCAL_PATH)/CHANGES.md
46+
@$(HOST_PYTHON) $(LOCAL_PATH)/build_info.py \
47+
$(LOCAL_PATH) \
48+
-i $(LOCAL_PATH)/build_info.h.tmpl \
49+
-o $(GLSLANG_BUILD_INFO_H)
50+
@echo "[$(TARGET_ARCH_ABI)] Generate : $(GLSLANG_BUILD_INFO_H) <= CHANGES.md"
51+
endef
52+
$(eval $(call gen_glslang_build_info_h))
53+
3654
GLSLANG_OS_FLAGS := -DGLSLANG_OSINCLUDE_UNIX
3755
# AMD and NV extensions are turned on by default in upstream Glslang.
3856
GLSLANG_DEFINES:= -DAMD_EXTENSIONS -DNV_EXTENSIONS -DENABLE_HLSL $(GLSLANG_OS_FLAGS)
@@ -55,31 +73,38 @@ LOCAL_C_INCLUDES:=$(LOCAL_PATH)/OGLCompiler
5573
LOCAL_STATIC_LIBRARIES:=OSDependent
5674
include $(BUILD_STATIC_LIBRARY)
5775

58-
# Build Glslang's HLSL parser library.
76+
# Build the stubbed HLSL library.
77+
# The HLSL source is now directly referenced by the glslang static library
78+
# instead.
5979
include $(CLEAR_VARS)
6080
LOCAL_MODULE:=HLSL
6181
LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti $(GLSLANG_DEFINES)
6282
LOCAL_SRC_FILES:= \
63-
glslang/HLSL/hlslAttributes.cpp \
64-
glslang/HLSL/hlslGrammar.cpp \
65-
glslang/HLSL/hlslOpMap.cpp \
66-
glslang/HLSL/hlslParseables.cpp \
67-
glslang/HLSL/hlslParseHelper.cpp \
68-
glslang/HLSL/hlslScanContext.cpp \
69-
glslang/HLSL/hlslTokenStream.cpp
83+
hlsl/stub.cpp
7084
LOCAL_C_INCLUDES:=$(LOCAL_PATH) \
7185
$(LOCAL_PATH)/glslang/HLSL
7286
include $(BUILD_STATIC_LIBRARY)
7387

7488
include $(CLEAR_VARS)
7589
GLSLANG_OUT_PATH=$(if $(call host-path-is-absolute,$(TARGET_OUT)),$(TARGET_OUT),$(abspath $(TARGET_OUT)))
7690

91+
# ShaderLang.cpp depends on the generated build_info.h
92+
$(LOCAL_PATH)/glslang/MachineIndependent/ShaderLang.cpp: \
93+
$(GLSLANG_BUILD_INFO_H)
94+
7795
LOCAL_MODULE:=glslang
7896
LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti $(GLSLANG_DEFINES)
7997
LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)
8098
LOCAL_SRC_FILES:= \
8199
glslang/GenericCodeGen/CodeGen.cpp \
82100
glslang/GenericCodeGen/Link.cpp \
101+
glslang/HLSL/hlslAttributes.cpp \
102+
glslang/HLSL/hlslGrammar.cpp \
103+
glslang/HLSL/hlslOpMap.cpp \
104+
glslang/HLSL/hlslParseables.cpp \
105+
glslang/HLSL/hlslParseHelper.cpp \
106+
glslang/HLSL/hlslScanContext.cpp \
107+
glslang/HLSL/hlslTokenStream.cpp \
83108
glslang/MachineIndependent/attribute.cpp \
84109
glslang/MachineIndependent/Constant.cpp \
85110
glslang/MachineIndependent/glslang_tab.cpp \
@@ -109,14 +134,19 @@ LOCAL_SRC_FILES:= \
109134
glslang/MachineIndependent/preprocessor/PpTokens.cpp
110135
LOCAL_C_INCLUDES:=$(LOCAL_PATH) \
111136
$(LOCAL_PATH)/glslang/MachineIndependent \
137+
$(GLSLANG_GENERATED_INCLUDEDIR) \
112138
$(GLSLANG_OUT_PATH)
113139
LOCAL_STATIC_LIBRARIES:=OSDependent OGLCompiler HLSL
114140
include $(BUILD_STATIC_LIBRARY)
115141

116142
include $(CLEAR_VARS)
143+
144+
# GlslangToSpv.cpp depends on the generated build_info.h
145+
$(LOCAL_PATH)/SPIRV/GlslangToSpv.cpp: \
146+
$(GLSLANG_BUILD_INFO_H)
147+
117148
LOCAL_MODULE:=SPIRV
118149
LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti -Werror $(GLSLANG_DEFINES)
119-
LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)
120150
LOCAL_SRC_FILES:= \
121151
SPIRV/GlslangToSpv.cpp \
122152
SPIRV/InReadableOrder.cpp \
@@ -127,7 +157,9 @@ LOCAL_SRC_FILES:= \
127157
SPIRV/SpvTools.cpp \
128158
SPIRV/disassemble.cpp \
129159
SPIRV/doc.cpp
130-
LOCAL_C_INCLUDES:=$(LOCAL_PATH) $(LOCAL_PATH)/glslang/SPIRV
160+
LOCAL_C_INCLUDES:=$(LOCAL_PATH) \
161+
$(LOCAL_PATH)/glslang/SPIRV \
162+
$(GLSLANG_GENERATED_INCLUDEDIR)
131163
LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)/glslang/SPIRV
132164
LOCAL_STATIC_LIBRARIES:=glslang
133165
include $(BUILD_STATIC_LIBRARY)

BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ licenses(["notice"])
4343

4444
exports_files(["LICENSE"])
4545

46+
# Build information generation script
47+
py_binary(
48+
name = "build_info",
49+
srcs = ["build_info.py"],
50+
)
51+
52+
genrule(
53+
name = "gen_build_info_h",
54+
srcs = ["CHANGES.md", "build_info.h.tmpl"],
55+
outs = ["glslang/build_info.h"],
56+
cmd = "$(location build_info) $$(dirname $(location CHANGES.md)) -i $(location build_info.h.tmpl) -o $(location glslang/build_info.h)",
57+
tools = [":build_info"],
58+
)
59+
4660
COMMON_COPTS = select({
4761
"@bazel_tools//src/conditions:windows": [""],
4862
"//conditions:default": [
@@ -93,6 +107,7 @@ cc_library(
93107
"StandAlone/DirStackFileIncluder.h",
94108
"glslang/OSDependent/osinclude.h",
95109
"glslang/Public/ShaderLang.h",
110+
":gen_build_info_h",
96111
],
97112
copts = COMMON_COPTS,
98113
defines = [

BUILD.gn

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,29 @@ if (defined(is_fuchsia_tree) && is_fuchsia_tree) {
4646
_configs_to_add = [ "//build/config/compiler:no_chromium_code" ]
4747
}
4848

49+
action("glslang_build_info") {
50+
script = "build_info.py"
51+
52+
src_dir = "."
53+
changes_file = "CHANGES.md"
54+
template_file = "build_info.h.tmpl"
55+
out_file = "${target_gen_dir}/include/glslang/build_info.h"
56+
57+
inputs = [
58+
changes_file,
59+
script,
60+
template_file,
61+
]
62+
outputs = [
63+
out_file
64+
]
65+
args = [
66+
rebase_path(src_dir, root_build_dir),
67+
"-i", rebase_path(template_file, root_build_dir),
68+
"-o", rebase_path(out_file, root_build_dir),
69+
]
70+
}
71+
4972
spirv_tools_dir = glslang_spirv_tools_dir
5073
if (!defined(glslang_angle)) {
5174
glslang_angle = false
@@ -109,7 +132,6 @@ template("glslang_sources_common") {
109132
"glslang/Include/Types.h",
110133
"glslang/Include/arrays.h",
111134
"glslang/Include/intermediate.h",
112-
"glslang/Include/revision.h",
113135
"glslang/MachineIndependent/Constant.cpp",
114136
"glslang/MachineIndependent/InfoSink.cpp",
115137
"glslang/MachineIndependent/Initialize.cpp",
@@ -216,13 +238,18 @@ template("glslang_sources_common") {
216238
]
217239
}
218240

241+
deps = [ ":glslang_build_info" ]
242+
219243
if (invoker.enable_opt) {
220-
deps = [
244+
deps += [
245+
":glslang_build_info",
221246
"${spirv_tools_dir}:spvtools_opt",
222247
"${spirv_tools_dir}:spvtools_val",
223248
]
224249
}
225250

251+
include_dirs = [ "${target_gen_dir}/include" ]
252+
226253
configs -= _configs_to_remove
227254
configs += _configs_to_add
228255
}
@@ -265,6 +292,8 @@ executable("glslang_validator") {
265292
]
266293
public_configs = [ ":glslang_hlsl" ]
267294

295+
include_dirs = [ "${target_gen_dir}/include" ]
296+
268297
configs -= _configs_to_remove
269298
configs += _configs_to_add
270299
}

CHANGES.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Revision history for `glslang`
2+
3+
All notable changes to this project will be documented in this file.
4+
This project adheres to [Semantic Versioning](https://semver.org/).
5+
6+
## 10.15.3847-dev 2020-06-16
7+
8+
### Breaking changes
9+
10+
* The following files have been removed:
11+
* `glslang/include/revision.h`
12+
* `glslang/include/revision.template`
13+
14+
The `GLSLANG_MINOR_VERSION` and `GLSLANG_PATCH_LEVEL` defines have been removed
15+
from the public headers. \
16+
Instead each build script now uses the new `build_info.py`
17+
script along with the `build_info.h.tmpl` and this `CHANGES.md` file to generate
18+
the glslang build-time generated header `glslang/build_info.h`.
19+
20+
The new public API to obtain the `glslang` version is `glslang::GetVersion()`.
21+
22+
### Other changes
23+
* `glslang` shared objects produced by CMake are now `SONAME` versioned using
24+
[Semantic Versioning 2.0.0](https://semver.org/).

CMakeLists.txt

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ if(BUILD_SHARED_LIBS)
5757
set(LIB_TYPE SHARED)
5858
endif()
5959

60+
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
61+
# This logic inside SPIRV-Tools, which can upset build target dependencies
62+
# if changed after targets are already defined. To prevent these issues,
63+
# ensure CMAKE_BUILD_TYPE is assigned early and at the glslang root scope.
64+
message(STATUS "No build type selected, default to Debug")
65+
set(CMAKE_BUILD_TYPE "Debug")
66+
endif()
67+
6068
option(SKIP_GLSLANG_INSTALL "Skip installation" ${SKIP_GLSLANG_INSTALL})
6169
if(NOT ${SKIP_GLSLANG_INSTALL})
6270
set(ENABLE_GLSLANG_INSTALL ON)
@@ -221,12 +229,54 @@ endfunction(glslang_set_link_args)
221229

222230
# CMake needs to find the right version of python, right from the beginning,
223231
# otherwise, it will find the wrong version and fail later
224-
if(BUILD_EXTERNAL AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/External)
225-
find_package(PythonInterp 3 REQUIRED)
226-
227-
# We depend on these for later projects, so they should come first.
228-
add_subdirectory(External)
229-
endif()
232+
find_package(PythonInterp 3 REQUIRED)
233+
234+
# Root directory for build-time generated include files
235+
set(GLSLANG_GENERATED_INCLUDEDIR "${CMAKE_BINARY_DIR}/include")
236+
237+
################################################################################
238+
# Build version information generation
239+
################################################################################
240+
set(GLSLANG_CHANGES_FILE "${CMAKE_SOURCE_DIR}/CHANGES.md")
241+
set(GLSLANG_BUILD_INFO_PY "${CMAKE_SOURCE_DIR}/build_info.py")
242+
set(GLSLANG_BUILD_INFO_H_TMPL "${CMAKE_SOURCE_DIR}/build_info.h.tmpl")
243+
set(GLSLANG_BUILD_INFO_H "${GLSLANG_GENERATED_INCLUDEDIR}/glslang/build_info.h")
244+
245+
# Command to build the build_info.h file
246+
add_custom_command(
247+
OUTPUT ${GLSLANG_BUILD_INFO_H}
248+
COMMAND ${PYTHON_EXECUTABLE} "${GLSLANG_BUILD_INFO_PY}"
249+
${CMAKE_CURRENT_SOURCE_DIR}
250+
"-i" ${GLSLANG_BUILD_INFO_H_TMPL}
251+
"-o" ${GLSLANG_BUILD_INFO_H}
252+
DEPENDS ${GLSLANG_BUILD_INFO_PY}
253+
${GLSLANG_CHANGES_FILE}
254+
${GLSLANG_BUILD_INFO_H_TMPL}
255+
COMMENT "Generating ${GLSLANG_BUILD_INFO_H}")
256+
257+
# Target to build the build_info.h file
258+
add_custom_target(glslang-build-info DEPENDS ${GLSLANG_BUILD_INFO_H})
259+
260+
# Populate the CMake GLSLANG_VERSION* variables with the build version
261+
# information.
262+
execute_process(
263+
COMMAND ${PYTHON_EXECUTABLE} "${GLSLANG_BUILD_INFO_PY}"
264+
${CMAKE_CURRENT_SOURCE_DIR} "<major>.<minor>.<patch><-flavor>;<major>;<minor>;<patch>;<flavor>"
265+
OUTPUT_VARIABLE "GLSLANG_VERSIONS"
266+
OUTPUT_STRIP_TRAILING_WHITESPACE)
267+
list(GET "GLSLANG_VERSIONS" 0 "GLSLANG_VERSION")
268+
list(GET "GLSLANG_VERSIONS" 1 "GLSLANG_VERSION_MAJOR")
269+
list(GET "GLSLANG_VERSIONS" 2 "GLSLANG_VERSION_MINOR")
270+
list(GET "GLSLANG_VERSIONS" 3 "GLSLANG_VERSION_PATCH")
271+
list(GET "GLSLANG_VERSIONS" 4 "GLSLANG_VERSION_FLAVOR")
272+
configure_file(${GLSLANG_CHANGES_FILE} "${CMAKE_CURRENT_BINARY_DIR}/CHANGES.md") # Required to re-run cmake on version change
273+
274+
# glslang_add_build_info_dependency() adds the glslang-build-info dependency and
275+
# generated include directories to target.
276+
function(glslang_add_build_info_dependency target)
277+
target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${GLSLANG_GENERATED_INCLUDEDIR}>)
278+
add_dependencies(${target} glslang-build-info)
279+
endfunction()
230280

231281
# glslang_only_export_explicit_symbols() makes the symbol visibility hidden by
232282
# default for <target> when building shared libraries, and sets the
@@ -256,6 +306,11 @@ else()
256306
message(NOTICE "Your CMake version is ${CMAKE_VERSION}. Update to at least 3.16 to enable precompiled headers to speed up incremental builds")
257307
endif()
258308

309+
if(BUILD_EXTERNAL AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/External)
310+
# We depend on these for later projects, so they should come first.
311+
add_subdirectory(External)
312+
endif()
313+
259314
if(NOT TARGET SPIRV-Tools-opt)
260315
set(ENABLE_OPT OFF)
261316
endif()

SPIRV/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ add_library(SPIRV ${LIB_TYPE} ${SOURCES} ${HEADERS})
7272
set_property(TARGET SPIRV PROPERTY FOLDER glslang)
7373
set_property(TARGET SPIRV PROPERTY POSITION_INDEPENDENT_CODE ON)
7474
target_include_directories(SPIRV PUBLIC
75-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
76-
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
75+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
76+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
77+
78+
glslang_add_build_info_dependency(SPIRV)
7779

7880
if (ENABLE_SPVREMAPPER)
7981
add_library(SPVRemapper ${LIB_TYPE} ${SPVREMAP_SOURCES} ${SPVREMAP_HEADERS})
@@ -95,8 +97,8 @@ if(ENABLE_OPT)
9597
)
9698
target_link_libraries(SPIRV PRIVATE MachineIndependent SPIRV-Tools-opt)
9799
target_include_directories(SPIRV PUBLIC
98-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../External>
99-
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/External>)
100+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../External>
101+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/External>)
100102
else()
101103
target_link_libraries(SPIRV PRIVATE MachineIndependent)
102104
endif(ENABLE_OPT)

SPIRV/GlslangToSpv.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ namespace spv {
5656
#include "../glslang/MachineIndependent/localintermediate.h"
5757
#include "../glslang/MachineIndependent/SymbolTable.h"
5858
#include "../glslang/Include/Common.h"
59-
#include "../glslang/Include/revision.h"
59+
60+
// Build-time generated includes
61+
#include "glslang/build_info.h"
6062

6163
#include <fstream>
6264
#include <iomanip>
@@ -8689,9 +8691,10 @@ void OutputSpvHex(const std::vector<unsigned int>& spirv, const char* baseName,
86898691
out.open(baseName, std::ios::binary | std::ios::out);
86908692
if (out.fail())
86918693
printf("ERROR: Failed to open file: %s\n", baseName);
8692-
out << "\t// " <<
8693-
GetSpirvGeneratorVersion() << "." << GLSLANG_MINOR_VERSION << "." << GLSLANG_PATCH_LEVEL <<
8694-
std::endl;
8694+
out << "\t// " <<
8695+
GetSpirvGeneratorVersion() <<
8696+
GLSLANG_VERSION_MAJOR << "." << GLSLANG_VERSION_MINOR << "." << GLSLANG_VERSION_PATCH <<
8697+
GLSLANG_VERSION_FLAVOR << std::endl;
86958698
if (varName != nullptr) {
86968699
out << "\t #pragma once" << std::endl;
86978700
out << "const uint32_t " << varName << "[] = {" << std::endl;

StandAlone/StandAlone.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#include "Worklist.h"
4545
#include "DirStackFileIncluder.h"
4646
#include "./../glslang/Include/ShHandle.h"
47-
#include "./../glslang/Include/revision.h"
4847
#include "./../glslang/Public/ShaderLang.h"
4948
#include "../SPIRV/GlslangToSpv.h"
5049
#include "../SPIRV/GLSL.std.450.h"
@@ -62,6 +61,9 @@
6261

6362
#include "../glslang/OSDependent/osinclude.h"
6463

64+
// Build-time generated includes
65+
#include "glslang/build_info.h"
66+
6567
extern "C" {
6668
GLSLANG_EXPORT void ShOutputHtml();
6769
}
@@ -1278,13 +1280,13 @@ int singleMain()
12781280
#endif
12791281

12801282
if (Options & EOptionDumpBareVersion) {
1281-
printf("%d.%d.%d\n",
1282-
glslang::GetSpirvGeneratorVersion(), GLSLANG_MINOR_VERSION, GLSLANG_PATCH_LEVEL);
1283+
printf("%d:%d.%d.%d%s\n", glslang::GetSpirvGeneratorVersion(), GLSLANG_VERSION_MAJOR, GLSLANG_VERSION_MINOR,
1284+
GLSLANG_VERSION_PATCH, GLSLANG_VERSION_FLAVOR);
12831285
if (workList.empty())
12841286
return ESuccess;
12851287
} else if (Options & EOptionDumpVersions) {
1286-
printf("Glslang Version: %d.%d.%d\n",
1287-
glslang::GetSpirvGeneratorVersion(), GLSLANG_MINOR_VERSION, GLSLANG_PATCH_LEVEL);
1288+
printf("Glslang Version: %d:%d.%d.%d%s\n", glslang::GetSpirvGeneratorVersion(), GLSLANG_VERSION_MAJOR,
1289+
GLSLANG_VERSION_MINOR, GLSLANG_VERSION_PATCH, GLSLANG_VERSION_FLAVOR);
12881290
printf("ESSL Version: %s\n", glslang::GetEsslVersionString());
12891291
printf("GLSL Version: %s\n", glslang::GetGlslVersionString());
12901292
std::string spirvVersion;

0 commit comments

Comments
 (0)