Skip to content

Commit

Permalink
Stop requiring vcvarsall.bat before build_mozc.py
Browse files Browse the repository at this point in the history
With this commit 'vcvarsall.bat' (and its variant) are no longer
requires to be executed before running 'build_mozc.py', like
'build_qt.py' has never required 'vcvarsall.bat' (and its variant) [1].

'--vcvarsall_path' option, which is available in 'build_qt.py' [2],
is also available to explicitly specify a custom path of vcvarsall.bat
as follows.

  build_mozc.py --vcvarsall_path=C:\VS\VC\Auxiliary\Build\vcvarsall.bat

Overall this commit should make our build instructions simpler and
easier to keep maintaining.

Closes #923.

#codehealth

 [1]: baf4188
 [2]: c777896

PiperOrigin-RevId: 629293616
  • Loading branch information
yukawa authored and hiroyuki-komatsu committed Apr 30, 2024
1 parent fcbd2d3 commit 1d82d68
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,12 @@ jobs:
shell: cmd
working-directory: .\src
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsamd64_x86.bat"
python build_mozc.py gyp
- name: build package
shell: cmd
working-directory: .\src
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsamd64_x86.bat"
python build_mozc.py build -c Release package
- name: upload Mozc64.msi
Expand Down Expand Up @@ -110,14 +108,12 @@ jobs:
shell: cmd
working-directory: .\src
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsamd64_x86.bat"
python build_mozc.py gyp --noqt --msvs_version=2022
- name: runtests
shell: cmd
working-directory: .\src
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsamd64_x86.bat"
python build_mozc.py runtests -c Debug
# actions/cache works without this job, but having this would increase the likelihood of cache hit
Expand Down
12 changes: 0 additions & 12 deletions docs/build_mozc_in_windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ git clone https://github.com/google/mozc.git
cd mozc\src
python build_tools/update_deps.py
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsamd64_x86.bat"
python build_tools/build_qt.py --release --confirm_license
python build_mozc.py gyp
python build_mozc.py build -c Release package
Expand Down Expand Up @@ -76,15 +73,6 @@ You can skip this step if you would like to manually download these libraries.

## Build

### Setup Build system

If you have not set up the build system in your command prompt, you might need
to execute the setup command like this.

```
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsamd64_x86.bat"
```

### Build Qt

```
Expand Down
17 changes: 12 additions & 5 deletions src/build_mozc.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
from build_tools.util import RemoveFile
from build_tools.util import RunOrDie
from build_tools.util import RunOrDieError
from build_tools.vs_util import get_vs_env_vars

SRC_DIR = '.'
OSS_SRC_DIR = '.'
Expand Down Expand Up @@ -252,6 +253,8 @@ def ParseGypOptions(args):
parser.add_option('--msvs_version', dest='msvs_version',
default='2022',
help='Version of the Visual Studio.')
parser.add_option('--vcvarsall_path', help='Path of vcvarsall.bat',
default=None)

if IsWindows() or IsMac():
parser.add_option('--qtdir', dest='qtdir',
Expand Down Expand Up @@ -373,6 +376,15 @@ def UpdateEnvironmentFilesForWindows(out_dir):

def GypMain(options, unused_args):
"""The main function for the 'gyp' command."""
if IsWindows():
# GYP captures environment variables while running so setting them up as if
# the developer manually executed 'vcvarsall.bat' command. Otherwise we end
# up having to explain how to do that for both cmd.exe and PowerShell.
# See https://github.com/google/mozc/pull/923
env_vars = get_vs_env_vars('x64', options.vcvarsall_path)
for (key, value) in env_vars.items():
os.environ[key] = value

# Generate a version definition file.
logging.info('Generating version definition file...')
template_path = '%s/%s' % (OSS_SRC_DIR, options.version_file)
Expand Down Expand Up @@ -863,11 +875,6 @@ def main():
command = sys.argv[1]
args = sys.argv[2:]

if IsWindows() and (not os.environ.get('VCToolsRedistDir', '')):
print('VCToolsRedistDir is not defined.')
print('Please use Developer Command Prompt or run vcvarsamd64_x86.bat')
return 1

if command == 'gyp':
(cmd_opts, cmd_args) = ParseGypOptions(args)
GypMain(cmd_opts, cmd_args)
Expand Down

0 comments on commit 1d82d68

Please sign in to comment.