<pre style='margin:0'>
Chris Jones (cjones051073) pushed a commit to branch master
in repository macports-ports.
</pre>
<p><a href="https://github.com/macports/macports-ports/commit/bee3e65349f0a316d9dcd583906acacd5b82f9cd">https://github.com/macports/macports-ports/commit/bee3e65349f0a316d9dcd583906acacd5b82f9cd</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit bee3e65349f0a316d9dcd583906acacd5b82f9cd
</span>Author: Chris Jones <jonesc@macports.org>
AuthorDate: Tue Mar 23 15:45:07 2021 +0000
<span style='display:block; white-space:pre;color:#404040;'> bazel PG: Rework to use standard build settings instead of redefining entire build phase
</span>---
_resources/port1.0/group/bazel-1.0.tcl | 111 ++++++++++++++++++++++-----------
1 file changed, 76 insertions(+), 35 deletions(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/_resources/port1.0/group/bazel-1.0.tcl b/_resources/port1.0/group/bazel-1.0.tcl
</span><span style='display:block; white-space:pre;color:#808080;'>index 02913a8687a..00ddc0734d2 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/_resources/port1.0/group/bazel-1.0.tcl
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/_resources/port1.0/group/bazel-1.0.tcl
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -10,6 +10,12 @@ namespace eval bazel { }
</span> options bazel.min_xcode
default bazel.min_xcode 10.2
<span style='display:block; white-space:pre;background:#e0ffe0;'>+options bazel.build_cmd
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+default bazel.build_cmd {[bazel::get_cmd]}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+options bazel.build_opts
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+default bazel.build_opts {[bazel::get_opts]}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> options bazel.build_target
default bazel.build_target ""
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -19,6 +25,12 @@ default bazel.post_build_cmd ""
</span> options bazel.version
default bazel.version "latest"
<span style='display:block; white-space:pre;background:#e0ffe0;'>+options bazel.max_idle_secs
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+default bazel.max_idle_secs 60
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+options bazel.extra_build_opts
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+default bazel.extra_build_opts ""
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> proc bazel::use_mp_clang {} {
global configure.compiler xcodeversion
return [ expr ( [ string match macports-clang-* ${configure.compiler} ] || [ vercmp ${xcodeversion} [option bazel.min_xcode] ] < 0 ) ]
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -36,14 +48,15 @@ configure.env-append JAVA_HOME=${java.home}
</span> build.env-append JAVA_HOME=${java.home}
build.env-append TMPDIR=${workpath}/tmp
<span style='display:block; white-space:pre;background:#ffe0e0;'>-proc set_bazel_dep { } {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+proc bazel::set_dep { } {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ui_debug "Defining bazel port dependency"
</span> if { [option bazel.version] eq "latest" } {
depends_build-append port:bazel
} else {
depends_build-append port:bazel-[option bazel.version]
}
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>-port::register_callback set_bazel_dep
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+port::register_callback bazel::set_dep
</span>
variant mkl description {Enable Intel Math Kernel Library support} { }
# Enable MKL by default on 10.12 and newer.
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -56,7 +69,7 @@ variant native description {Build from source for best native platform support}
</span> archive_sites
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>-proc get_base_arch {} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+proc bazel::get_base_arch {} {
</span> global configure.build_arch
# Currently only supports intel
if { ${configure.build_arch} eq "x86_64" } {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -67,7 +80,7 @@ proc get_base_arch {} {
</span>
supported_archs x86_64
if {![variant_isset native]} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set base_march [get_base_arch]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set base_march [bazel::get_base_arch]
</span> configure.env-append CC_OPT_FLAGS=${base_march}
build.env-append CC_OPT_FLAGS=${base_march}
notes "This version is built based on a base architecture for convenience,
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -75,13 +88,14 @@ if {![variant_isset native]} {
</span> customized for your machine, use the +native variant"
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>-proc bazel_set_env {} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+proc bazel::set_env {} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ui_debug "Setting Bazel Env"
</span> if { [bazel::use_mp_clang] } {
configure.env-append BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
build.env-append BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
}
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>-port::register_callback bazel_set_env
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+port::register_callback bazel::set_env
</span>
# Configure phase
# Remove all arguments
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -107,22 +121,14 @@ pre-configure {
</span> }
# If not native build, make sure not used...
if {![variant_isset native]} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set base_march [get_base_arch]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set base_march [bazel::get_base_arch]
</span> foreach f [ exec find ${worksrcpath}/ -name "configure" -or -name "configure.py" -or -name "CMakeLists.txt" -or -name "Makefile" -or -name "*.sh" ] {
reinplace -q "s|-march=native|${base_march}|g" ${f}
}
}
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>-# Limit the number of parallel jobs to the number of physical, not logical, cpus.
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-# First current setting to ensure we would be reducing the current setting.
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-set physicalcpus [sysctl hw.physicalcpu]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-if { ${build.jobs} > ${physicalcpus} } {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- build.jobs ${physicalcpus}
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-}
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-build {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+pre-build {
</span> # bazel cannot build if gcc is 'port selected'
# https://trac.macports.org/ticket/58569
# https://trac.macports.org/ticket/58679
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -134,20 +140,40 @@ build {
</span> ui_error "Once the build is complete, you can safely re-select your preferred gcc."
return -code error "build error"
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>- # Build using the wonderful bazel build system ...
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set bazel_cmd "bazel --max_idle_secs=60 --output_user_root=${workpath}"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# Limit the number of parallel jobs to the number of physical, not logical, cpus.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# First current setting to ensure we would be reducing the current setting.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+set physicalcpus [sysctl hw.physicalcpu]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+if { ${build.jobs} > ${physicalcpus} } {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ build.jobs ${physicalcpus}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# Bazel handles parallel builds its own way..
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+use_parallel_build no
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+proc bazel::get_cmd {} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ global bazel.max_idle_secs workpath
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # Generate the bazel build command
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set bazel_cmd "bazel --max_idle_secs=${bazel.max_idle_secs} --output_user_root=${workpath}"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if { [bazel::use_mp_clang] } {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set bazel_cmd "BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 ${bazel_cmd}"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {![variant_isset native]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set base_march [bazel::get_base_arch]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set bazel_cmd "CC_OPT_FLAGS=${base_march} ${bazel_cmd}"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ui_debug "Defined Bazel build command ${bazel_cmd}"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return ${bazel_cmd}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+proc bazel::get_opts {} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ global build.jobs configure.cc configure.cflags configure.cxxflags configure.ldflags
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # Bazel build options
</span> set bazel_build_opts "-s -c opt --verbose_failures --config=opt"
# Limit bazel resource utilisation
set bazel_build_opts "${bazel_build_opts} --jobs ${build.jobs} --local_ram_resources=HOST_RAM*0.5 --local_cpu_resources=HOST_CPUS*.5"
<span style='display:block; white-space:pre;background:#ffe0e0;'>- # Explicitly pass SDK https://github.com/bazelbuild/rules_go/issues/1554
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- # Check versioned SDK actually exists... https://trac.macports.org/ticket/60317
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- # Disable but keep the code below commented for reference, for now, as need to see how it plays out
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- # See https://trac.macports.org/ticket/62474
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- #if {[string first ${configure.sdk_version} ${configure.sdkroot}] != -1} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- # set bazel_build_opts "${bazel_build_opts} --macos_sdk_version=${configure.sdk_version}"
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- #} else {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- # ui_warn "configure.sdkroot='${configure.sdkroot}' does not match configure.sdk_version='${configure.sdk_version}'"
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- #}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # Extra user defined build options
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set bazel_build_opts "${bazel_build_opts} [option bazel.extra_build_opts]"
</span> # hack to try and transfer MP c, c++ and ld options to bazel...
foreach opt [list {*}${configure.cflags} ] {
set bazel_build_opts "${bazel_build_opts} --conlyopt '${opt}'"
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -160,21 +186,36 @@ build {
</span> }
if { [bazel::use_mp_clang] } {
set bazel_build_opts "${bazel_build_opts} --action_env CC=${configure.cc}"
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set bazel_cmd "BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 ${bazel_cmd}"
</span> }
if {[variant_isset mkl]} {
set bazel_build_opts "${bazel_build_opts} --config=mkl"
}
if {![variant_isset native]} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set base_march [get_base_arch]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set base_march [bazel::get_base_arch]
</span> set bazel_build_opts "${bazel_build_opts} --copt=${base_march}"
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set bazel_cmd "CC_OPT_FLAGS=${base_march} ${bazel_cmd}"
</span> }
<span style='display:block; white-space:pre;background:#ffe0e0;'>- ui_debug "Bazel build command : ${bazel_cmd}"
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- ui_debug "Bazel build options : ${bazel_build_opts}"
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- ui_debug "Bazel build target : [option bazel.build_target]"
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- # Run the build
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- system -W ${worksrcpath} "${bazel_cmd} build ${bazel_build_opts} [option bazel.build_target]"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ui_debug "Defined Bazel build options ${bazel_build_opts}"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return ${bazel_build_opts}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+proc bazel::configure_build {} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ global bazel.build_cmd bazel.build_opts bazel.build_target
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ global build.jobs build.cmd build.args build.post_args
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ui_debug "Configuring bazel build command and arguments"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ build.cmd "[option bazel.build_cmd]"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ build.args "[option bazel.build_opts]"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ build.post_args "[option bazel.build_target]"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ui_debug "Bazel build command : ${build.cmd}"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ui_debug "Bazel build options : ${build.args}"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ui_debug "Bazel build target : [option bazel.build_target]"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ui_debug "Bazel post-build cmd : [option bazel.post_build_cmd]"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+port::register_callback bazel::configure_build
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+post-build {
</span> # Post build command
system -W ${worksrcpath} "[option bazel.post_build_cmd]"
# Clean up
</pre><pre style='margin:0'>
</pre>