github.com/ajguerrer/rules_go@v0.20.3/windows.rst (about)

     1  Using rules_go on Windows
     2  =========================
     3  
     4  This is a list of notes from the last time I ran rules_go on Windows. This
     5  is not complete documentation yet, but will be expanded some time in the
     6  future. Bazel's support for Windows is changing and improving over time, so
     7  these instructions may be out of date.
     8  
     9  Preparation
    10  -----------
    11  
    12  These steps are completely optional.
    13  
    14  * Consider disabling Windows Defender, at least temporarily. Defender will
    15    block the Bazel download for 20+ minutes, presumably because
    16    some signature is not in place. This can be done in Windows Defender
    17    Security Center > App & Browser control > Check apps and files: Off.
    18  * Install VSCode. It has pretty good support for Go and a good terminal
    19    emulator.
    20  
    21  Install and configure dependencies
    22  ----------------------------------
    23  
    24  * Install msys2 from https://www.msys2.org/. This is needed to provide a bash
    25    environment for Bazel.
    26  
    27    * Follow the installation directions to the end, including
    28      running ``pacman -Syu`` and ``pacman -Su`` in the msys2 shell.
    29  
    30  * Install additional msys2 tools.
    31  
    32    * Run ``pacman -S mingw-w64-x86_64-gcc``. GCC is needed if you plan to build
    33      any cgo code. MSVC will not work with cgo. This is a Go limitation, not a
    34      Bazel limitation. cgo determines types of definitions by compiling specially
    35      crafted C files and parsing error messages. GCC or clang are specifically
    36      needed for this.
    37    * Run ``pacman -S patch``. ``patch`` is needed by ``git_repository`` and
    38      ``http_archive`` dependencies declared by rules_go. We use it to add
    39      and modify build files.
    40  
    41  * Add ``C:\msys64\usr\bin`` to ``PATH`` in order to locate ``patch`` and
    42    other DLLs.
    43  * Add ``C:\msys64\mingw64\bin`` to ``PATH`` in order to locate mingw DLLs.
    44    ``protoc`` and other host binaries will not run without these.
    45  * Set the environment variable ``BAZEL_SH`` to ``C:\msys64\usr\bin\bash.exe``.
    46    Bazel needs this to run shell scripts.
    47  * Set the environment variable ``CC`` to ``C:\msys64\mingw64\bin\gcc.exe``.
    48    Bazel uses this to configure the C/C++ toolchain.
    49  * Install the MSVC++ redistributable from
    50    https://www.microsoft.com/en-us/download/details.aspx?id=48145.
    51    Bazel itself depends on this.
    52  * Install Git from https://git-scm.com/download/win. The Git install should
    53    add the installed directory to your ``PATH`` automatically.
    54  
    55  Install bazel
    56  -------------
    57  
    58  * Download Bazel from https://github.com/bazelbuild/bazel/releases.
    59  * Move the binary to ``%APPDATA%\bin\bazel.exe``.
    60  * Add that directory to ``PATH``.
    61  * Confirm ``bazel version`` works.
    62  * Confirm you can run a C binary with
    63    ``bazel run --cpu=x64_windows --compiler=mingw-gcc //:target``.
    64  
    65  Confirm Go works
    66  ----------------
    67  
    68  * Copy boilerplate from rules_go.
    69  * Confirm that you can run a pure Go "hello world" binary with
    70    ``bazel run //:target``
    71  * Confirm you can run a cgo binary with
    72    ``bazel run --cpu=x64_windows --compiler=mingw-gcc //:target``
    73  * You may want to add ``build --cpu=x64_windows --compiler=mingw-gcc`` to
    74    a ``.bazelrc`` file in your project or in your home directory.