Skip to content

Commit

Permalink
Build without the deploy feature by default
Browse files Browse the repository at this point in the history
Build tags setup changed to:

* !nodeploy => withdeploy
* nodeploy => !withdeploy

Also move the deploy feature out into its own release archives.

See #12994 for the primary motivation for this change. But this also greatly reduces the number of dependencies in Hugo when you don't need this feature and cuts the binary size greatly.

Fixes #12994
  • Loading branch information
bep committed Oct 30, 2024
1 parent 62567d3 commit 6dde478
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 22 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

*.test
imports.*
imports.*
dist/
public/
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ COPY --from=xx / /
ARG TARGETPLATFORM
RUN xx-apk add musl-dev gcc g++

# Optionally set HUGO_BUILD_TAGS to "none" or "nodeploy" when building like so:
# docker build --build-arg HUGO_BUILD_TAGS=nodeploy .
# Optionally set HUGO_BUILD_TAGS to "none" or "withdeploy" when building like so:
# docker build --build-arg HUGO_BUILD_TAGS=withdeploy .
#
# We build the extended version by default.
ARG HUGO_BUILD_TAGS="extended"
Expand Down
4 changes: 2 additions & 2 deletions commands/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !nodeploy
// +build !nodeploy
//go:build withdeploy
// +build withdeploy

// Copyright 2024 The Hugo Authors. All rights reserved.
//
Expand Down
7 changes: 4 additions & 3 deletions commands/deploy_off.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build nodeploy
// +build nodeploy
//go:build !withdeploy
// +build !withdeploy

// Copyright 2024 The Hugo Authors. All rights reserved.
//
Expand All @@ -31,6 +31,7 @@ package commands

import (
"context"
"errors"

"github.com/bep/simplecobra"
"github.com/spf13/cobra"
Expand All @@ -40,7 +41,7 @@ func newDeployCommand() simplecobra.Commander {
return &simpleCommand{
name: "deploy",
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
return nil
return errors.New("deploy not supported in this version of Hugo; install a release with 'with-deploy' in the archive filename or build yourself with the 'withdeploy' build tag. Also see https://github.com/gohugoio/hugo/pull/12995")
},
withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.Hidden = true
Expand Down
4 changes: 2 additions & 2 deletions deploy/cloudfront.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !nodeploy
// +build !nodeploy
//go:build withdeploy
// +build withdeploy

package deploy

Expand Down
4 changes: 2 additions & 2 deletions deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !nodeploy
// +build !nodeploy
//go:build withdeploy
// +build withdeploy

package deploy

Expand Down
4 changes: 2 additions & 2 deletions deploy/deploy_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !solaris && !nodeploy
// +build !solaris,!nodeploy
//go:build !solaris && withdeploy
// +build !solaris,withdeploy

package deploy

Expand Down
4 changes: 2 additions & 2 deletions deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !nodeploy
// +build !nodeploy
//go:build withdeploy
// +build withdeploy

package deploy

Expand Down
4 changes: 2 additions & 2 deletions deploy/deployconfig/deployConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !nodeploy
// +build !nodeploy
//go:build withdeploy
// +build withdeploy

package deployconfig

Expand Down
4 changes: 2 additions & 2 deletions deploy/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !nodeploy
// +build !nodeploy
//go:build withdeploy
// +build withdeploy

package deploy

Expand Down
22 changes: 22 additions & 0 deletions hugoreleaser.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ archive_alias_replacements = { "linux-amd64.tar.gz" = "Linux-64bit.tar.gz" }
[[builds.os.archs]]
goarch = "amd64"

[[builds]]
path = "container1/unix/extended-withdeploy"

[builds.build_settings]
flags = ["-buildmode", "exe", "-tags", "extended,withdeploy"]
env = ["CGO_ENABLED=1"]

[[builds.os]]
goos = "darwin"
[builds.os.build_settings]
env = ["CGO_ENABLED=1", "CC=o64-clang", "CXX=o64-clang++"]
[[builds.os.archs]]
goarch = "universal"
[[builds.os]]
goos = "linux"
[[builds.os.archs]]
goarch = "amd64"

[[builds]]
path = "container2/linux/extended"

Expand Down Expand Up @@ -173,6 +191,10 @@ archive_alias_replacements = { "linux-amd64.tar.gz" = "Linux-64bit.tar.gz" }
paths = ["builds/container1/unix/extended/**"]
[archives.archive_settings]
name_template = "{{ .Project }}_extended_{{ .Tag | trimPrefix `v` }}_{{ .Goos }}-{{ .Goarch }}"
[[archives]]
paths = ["builds/container1/unix/extended-withdeploy/**"]
[archives.archive_settings]
name_template = "{{ .Project }}_extended_with_deploy_{{ .Tag | trimPrefix `v` }}_{{ .Goos }}-{{ .Goarch }}"
[[archives]]
# Only extended builds in container2.
paths = ["builds/container2/**"]
Expand Down
2 changes: 1 addition & 1 deletion magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func buildFlags() []string {
func buildTags() string {
// To build the extended Hugo SCSS/SASS enabled version, build with
// HUGO_BUILD_TAGS=extended mage install etc.
// To build without `hugo deploy` for smaller binary, use HUGO_BUILD_TAGS=nodeploy
// To build with `hugo deploy`, use HUGO_BUILD_TAGS=withdeploy
if envtags := os.Getenv("HUGO_BUILD_TAGS"); envtags != "" {
return envtags
}
Expand Down
2 changes: 1 addition & 1 deletion testscripts/commands/gen.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Test the gen commands.
# Note that adding new commands will require updating the NUM_COMMANDS value.
env NUM_COMMANDS=44
env NUM_COMMANDS=43

hugo gen -h
stdout 'Generate documentation for your project using Hugo''s documentation engine, including syntax highlighting for various programming languages\.'
Expand Down

0 comments on commit 6dde478

Please sign in to comment.