Golang newbie - keen to contribute

Hi all, I’m new to Go programming and want to contribute to Hugo.
Working my way through the Contribute to Hugo Development article and I’ve run into a problem:

mage -v check fails in go1.17.1 on Windows with this error:
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in %PATH%

This looks like a previous Hugo issue: Compiling and installing Hugo from source on Windows is getting a gcc error and fails · Issue #5798 · gohugoio/hugo · GitHub, which was closed and referred here, so am reluctant to open a new one (for now at least!)

I think the root cause is this Golang issue: https://github.com/golang/go/issues/47257 and I have the beginnings of an idea to resolve it in Hugo. I’m keen for any input and guidance the community can offer, and looking forward to getting involved!

You no longer need mage to build Hugo from source.

No idea what’s going on with that article (I don’t contribute to the Docs) maybe the others have reasons for not updating it (cc: @jmooring ).

Provided that you have Go installed and an up-to-date local clone of the Hugo master repository then from within that directory simply execute the following command in the console:

go build 

Or if you need the Hugo extended version run:

go build -tags extended

With the above you will get the latest Hugo-DEV version from source.

And that’s it really.

P.S. Since GitHub introduced a simple button in their web GUI to fetch the latest from upstream I simply use it and then locally from within my Hugo fork I simply run git pull to fetch the latest.

Thanks for the tip re mage, I’ll treat that article with caution. (Happy to help with a rewrite if that’s needed – once I get my head around this.)

At this point though I don’t think mage is the problem. go build works fine for me, whether mage executes it, or I run it direct.

The error occurs on go test -race ./... and it’s the same whether triggered by mage or run direct.

Additional info:

Here’s the full command issued by mage:

go test -race ./... -buildmode exe -tags none

Again, this produces the same error when I run it direct.

Last updated: 2024-02-03T22:54:01-08:00

This post is outdated. Please refer to the build from source section of the Hugo installation instructions for Windows.


When building the extended flavor of Hugo from source on Windows, you will need Go and the GCC compiler.

To install the GCC compiler:

  1. Download and install 7-Zip.

  2. Download Mingw-w64. You want the file with “posix-seh” in its name.

  3. Extract the archive with 7-Zip, then move the mingw64 directory to the root of your C:\ drive.

    C:\MINGW64
    ├───bin
    ├───etc
    ├───include
    ├───lib
    ├───libexec 
    ├───licenses
    ├───opt
    ├───share
    └───x86_64-w64-mingw32
    
  4. Update the PATH environment variable

    • Right click on the Start menu icon, choose Run, then paste:

      rundll32.exe sysdm.cpl,EditEnvironmentVariables

    • Under “User variables” select PATH, press Edit, press New, then paste:

      C:\mingw64\bin

  5. Verify that gcc is installed and in your PATH. Open a cmd window then type:

    gcc --version

  6. Now compile the extended version of Hugo. Change to the directory containing the Hugo codebase, then type:

    go install -tags extended

    Be patient; it will take a while.

  7. Verify the location of the executable by typing where hugo. This should display something like:

    C:\Users\joe\go\bin\hugo.exe

  8. Verify the version by typing hugo version. This should display something like:

    hugo v0.106.0-DEV-52ea07d2eb9c581015f85c0d2d6973640a62281b+extended windows/amd64 BuildDate=2022-11-01T17:45:34Z

3 Likes

This worked - thank you!
I did have GCC installed but incorrectly by the looks of things, and I guess Go wasn’t finding it.
So the install command succeeds and hugo version returns this:

Hugo Static Site Generator v0.56.3/extended windows/amd64 BuildDate: unknown

The version’s a long way behind yours but hopefully not unexpected (remember I’m following the steps here: https://gohugo.io/contribute/development/ so am in a fork of master (currently unchanged).)

No doubt I’ll have more questions - need to get the tests running and passing now - but will start a new thread for anything arising from that.

Thanks again - everyone - for the input.

Upgrade your source to head before spending time on anything else.

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.