MDN will be in maintenance mode on Wednesday September 20th, starting at 10 AM Pacific / 5 PM UTC, for about 1 hour.

翻譯不完整。請協助 翻譯此英文文件

在 Windows 上編譯 Firefox

感謝您幫助我們編譯這個用在世界最知名的作業系統上,世界上最好的瀏覽器。這份文件將幫助您可以在自己的設備上建立環境來編譯並黑客自己獨有版本的 Firefox。

建立環境並不困難,但她需要一點時間,我們將需要下載大量的 bytes!就算是在一個快速網路下,仍然可能會花十幾分鐘來下載,最常甚至可能到一兩個小時。

詳細步驟在這業的下方,但這份快速上手的指引將讓您建立起來並運作:

事先準備

To build Firefox on Windows, you need a 64-bit version of Windows 7 or later and about 40 GB of free space on your hard drive . You can make sure your version of Windows is 64-bit on Windows 7 by right-clicking Computer in your Start menu, clicking Properties and then System. On Windows 8.1 and Windows 10, right-clicking the Windows menu button and choosing System will show you the same information. You can alternatively press Win + Pause Break on your keyboard on any version of Windows.

Next, we want to start on a solid foundation: make sure you’re up to date with Windows Update and then we’ll get moving.

Visual Studio 2015

目前官方是使用 Visual Studio 2015 來編譯。 To use it, download and install Visual Studio Community 2015 Update 3 from Microsoft (warning : current version is now Visual Studio 2017, so to get exactly the 2015 update 3 version with the link above, you need to go to the "Download" section", then choose "Visual Studio Community 2015 with Update 3" and then download it, but you can also use Visual Studio 2017, see next section below). If you have an earlier version of Visual Studio, you'll need to upgrade; Firefox relies on C++ features that aren't supported in older versions of Visual Studio. Do not accept the default configuration. Instead, select Programming Languages > Visual C++ > Common Tools for Visual C++ 2015. This option is required for Rust. After installation, be sure to Launch Visual Studio 2015 from the GUI to complete the first time run procedure to associate this installation with an account.  Otherwise, you will be running an evaluation version which will not properly update via Windows Update.

Next, you need to download and install the Cumulative Servicing Release for Microsoft Visual Studio 2015 Update 3 (KB3165756).

Visual Studio 2017

您也可以使用 Visual Studio 2017, by 下載 community edition。當安裝時,記得點勾選:

  • "Desktop development with C++" (最上方)
  • "Game development with C++" (最後群組的第二項)

並且確定桌面開發的工作項目欄位中的以下組件是有被勾選且將會被安裝。

  • VC++ 2017 v<version> toolset (x86,x64)
  • Windows 10 SDK (<version>) for Desktop C++ x86 and x64
  • Visual C++ ATL support

安裝完後請跑一次 GUI 的介面,來確保它完成任何首次運作的任務,並將安裝與您的帳戶連結。

需要的工具

Rust

安裝 Rust。參見 Rust 平台支援 頁面來找到任何您安裝上遇到的問題。

MAPI Header Files (for Thunderbird or SeaMonkey build)

If you are going to be building Thunderbird or SeaMonkey, check to see if C:\Program Files (x86)\Windows Kits\8.1\Include\shared\MAPIX.h exists. If it does not, install the Outlook 2010: MAPI Header Files kit. Then copy the header files in C:\Office 2010 Developer Resources\Outlook 2010 MAPI Headers to both:

  • C:\Program Files (x86)\Windows Kits\8.1\Include\shared
  • C:\Program Files (x86)\Windows Kits\10\Include\10.0.nnnnn.0\shared, where nnnnn is the highest number present on the system.

MozillaBuild

最後從 Molliza 下載 MozillaBuild 套件。同意所有事項並將安裝預設目錄設為 c:\mozilla-build\。在一些版本的 Windows 上會出現  「重新安裝來完成安裝」,您需要點選同意並執行他的步驟。

一旦完成,將 c:\mozilla-build\start-shell.bat 捷徑放到桌面上,將幫助您以後開發更加方便。

與社群聯繫

That last step can take some time. While it’s finishing you should take a moment to sign up for a Bugzilla account!

Bugzilla.mozilla.org is Mozilla’s issue tracker. To comment on a bug or submit a patch you’ll need a Bugzilla account; you can use your GitHub account if you have one, or sign up for a Bugzilla account directly.

As well as Bugzilla, much of Mozilla’s internal communication happens over IRC. You can download Limechat here, and learn how to connect to Mozilla with IRC here. If you’re just getting started or have questions about getting set up you can join us in the #introduction channel, where some of our community members hang out to try and help new contributors get rolling.

建立檔案資源

這是最後一大步驟。 雙下點擊 start-shell.bat 於 c:\mozilla-build (或您剛剛建立的捷徑),將會開啟終端機視窗。

加上這行

PATH=$PATH:~/.cargo/bin

在任一  ~/.bash_profile  ~/.bash_login 或  ~/.profile.

在 C:\ 下建立一個資料夾叫  "mozilla-source" 並 cd 進去

cd c:/

mkdir mozilla-source

cd mozilla-source

接著您將用 Mercurial,我們的版本管理系統,抓取 Firefox 原始碼。輸入以下指令:

hg clone https://hg.mozilla.org/mozilla-central

hg 是 mercury(汞) 的化學代號。

當您等待的過程中可以看一下 Mercurial 文件 。他解釋 Mozilla 如何來做程式碼本本管理,並將改變加入源碼樹。

編譯 Firefox!

現在我們一切就緒,在您終端機輸入以下指令:

cd mozilla-central
mach bootstrap
mach build

"mach bootstrap"  步驟是處理各式各樣的相依檔案,並不在此文件介紹範圍內。

您已經上路了,即便是在現代機器上,這也需要一點時間,別氣餒!Firefox 相當的大,因為網路世界就是如此浩瀚。

加入Mozillians.org!

There’s one more thing you can do for yourself while you’re waiting: create an account for yourself on Mozillians. Mozillians is the Mozilla community directory, where you can connect with people who share your interests, projects or countries. This step is optional, but we think it will be worth your while.

一切就緒

當 mach build 完成,代表您已經從源始碼編譯自己版本的 Firefox,您可以輸入以下指令來測試:

mach run

現在你有自己版本的 Firefox 了。

If you saw an error here, look further down in this document for the "Troubleshooting" section - some antiviruses quarantine some of our tests, so you need to create execeptions for the "mozilla-source" and "mozilla-build" directories. Don't turn your antivirus off! Just add the exceptions.

現在是有趣的開始

You have the code, you’ve compiled Firefox. Fire it up with ./mach run and you’re ready to start hacking. The next steps are up to you: join us on IRC in the#introduction channel, follow StartMozilla on Twitter and find a bug to start working on.

Thank you for joining us and helping us make Firefox and the open Web better for everyone.

細節與故障排除

Hardware and software requirements

The Firefox build process is both I/O and CPU-intensive, and can take a long time to build even on modern hardware. Minimum and recommended hardware requirements for Mozilla development are:

  • At least 4 GB of RAM. 8 GB or more is recommended, and more is always better.
  • 35 GB free disk space. This amount of disk space accommodates Visual Studio 2015 Community Edition, the required SDKs, the MozillaBuild package, the Mercurial source repository and enough free disk space to compile. A solid-state hard disk is recommended; the Firefox build process is I/O-intensive.
  • A 64-bit version of Windows 7 (Service Pack 1) or later. You can still build 32-bit Firefox on a 64-bit Windows installation.

總攬

The Mozilla build process requires many tools that are not preinstalled on most Windows  systems. In addition to Visual Studio, install MozillaBuild, a software bundle that includes the required versions of bash, GNU make, autoconf, Mercurial, and much more.

Firefox 48 and later build with Visual Studio 2015 in our official releases. You should be using Visual Studio 2015 to build all current versions of Firefox.

Firefox 37 through 47 build with Visual Studio 2013 (VC12) and possibly Visual Studio 2015 (although Visual Studio 2015 may not build every revision).

Earlier versions of Firefox build with older versions of Visual Studio.

Installing the build prerequisites

Complete each of these steps. Otherwise, you may not be able to build successfully. There are notes on these software requirements below.

  1. Make sure your system is up-to-date through Windows Update.
  2. Install Visual Studio Community 2015 (free). Be sure to install the "Common Tools for Visual C++ 2015", which requires a customized installation in Visual Studio 2015. Alternatively, you can also use a paid version of Visual Studio. The optional parts of the VS2015 Community install - including the Microsoft Foundation Classes for C++ - are not necessary to build Firefox. Earlier versions of Visual Studio are not supported; the Firefox codebase relies on C++ features that are not supported in VS2012 or earlier.
  3. Optionally, in addition to VS2015, you may want to also install Visual C++ 2008 Express (free) to compile some Python extensions used in the build system, because Python 2.7.x on Windows is built with that compiler by default. Note, if you want to use "mach resource-usage", "mach doctor", "mach android-emulator", or run talos tests locally, you should install it for building psutil.
  4. Download and install the MozillaBuild package, containing additional build tools. If you have Cygwin installed, read the note in the tips section. (After MozillaBuild's installer exits, if you see a Windows error dialog giving you the option to re-install with the 'correct settings', choose that option and after that all should be well.) More information about MozillaBuild and links to newer versions are available at https://wiki.mozilla.org/MozillaBuild.

Troubleshooting

In some circumstances, the following problems can arise:

Some antivirus and system protection software can dramatically slow or break the build process:

  • Windows Defender and some scanning antivirus products are known to have a major impact on build times. As one example, if you have have cloned mozilla-central successfully but ./mach build fails reporting a missing file, you are likely experiencing this problem. Our regression tests for well-known security bugs can include code samples that some antivirus software will identify as a threat, and will either quarantine or otherwise corrupt the files involved. To resolve this you will need to whitelist your source and object directories (the mozilla-source and mozilla-build directories) in Windows Defender or your antivirus software and if you're missing files, revert your source tree with the "hg update -C" command. Once this is done your next ./mach build should complete successfully.

Installing Visual Studio in a different language than the system can cause issues

  • For example, having Visual Studio in french when the system is in english causes the build to spew a lot of include errors and finishes by a link error.

Please note that Mozilla will not build if the path to the installation folder of some tools contains spaces or other breaking characters such as pluses, quotation marks, or metacharacters.  The Visual Studio tools and SDKs are an exception -- they may be installed in a directory which contains spaces. It is strongly recommended that you accept the default settings for all installation locations.

MozillaBuild

The MozillaBuild package contains other software prerequisites necessary for building Mozilla, including the MSYS build environment, Mercurial, autoconf-2.13, CVS, Python, YASM, NSIS, and UPX, as well as optional but useful tools such as wget and emacs.

Download the current MozillaBuild package.

By default, the package installs to c:\mozilla-build. It is recommended to use the default path. Don't use a path that contains spaces. The installer does not modify the Windows registry. Note that some binaries may require Visual C++ Redistributable package to run.

MozillaBuild command prompt expectation setting: Note that the "UNIX-like" environment provided by MozillaBuild is only really useful for building and committing to the Mozilla source. Most command line tools you would expect in a modern Linux distribution are not present, and those tools that are provided can be as much as a decade or so old (especially those provided by MSYS). It's the old tools in particular that can cause problems, since they often don't behave as expected, are buggy, or don't support command line arguments that have been taken for granted for years. For example, copying a source tree using cp -rf src1 src2 does not work correctly because of an old version of cp (it gives "cp: will not create hard link" errors for some files). In short, MozillaBuild supports essential developer interactions with the Mozilla code, but beyond that don't be surprised if it trips you up in all sorts of exciting and unexpected ways.

Opening a MozillaBuild command prompt

After the prerequisites are installed, launch the start-shell.bat batch file using the Windows command prompt in the directory to which you installed MozillaBuild (c:\mozilla-build by default). This will launch an MSYS/BASH command prompt properly configured to build Firefox. All further commands should be executed in this command prompt window. (Note that this is not the same as what you get with the Windows CMD.EXE shell.)

Create a directory for the source

Note: You won't be able to build the Firefox source code if it's under a directory with spaces in the path (e.g., don't use "Documents and Settings"). You can pick any other location, such as a new directory c:/mozilla-source or c:/thunderbird-src. The build command prompt also tolerates "c:\" and  "/c/", but the former allows confusion with the windows command prompt, and the later is misinterpreted by some tools (at least MOZ_OBJDIR). The "C:/" syntax helps draw attention that the MozillaBuild command prompt is assumed from here on out since it provides configured environment and tools.

It's a sensible idea to create a new shallow directory, like "c:/mozilla-source" or "c:/thunderbird-src" dedicated solely to the code:

cd c:/; mkdir mozilla-source; cd mozilla-source

Keeping in mind the diagnostic hints below should you have issues, you are now ready to get the Firefox source and build; continue on to Simple Firefox build (Get_the_source), or another like Simple Thunderbird build (Get_the_source).

Command Prompt Tips and Caveats

  • To paste into this window, you must right-click on the window's title bar, move your cursor to the Edit menu, and click Paste. You can also set Quick Edit Mode in the Properties menu and right-click the window to paste your selection.
  • If you have Cygwin installed, make sure that the MozillaBuild directories come before any Cygwin directories in the search path enhanced by start-shell-msvc2015.bat (use echo $PATH to see your search path).
  • In the MSYS / BASH shell started by start-shell-msvc2015.bat, UNIX-style forward slashes (/) are used as path separators instead of the Windows-style backward slashes (\).  So if you want to change to the directory c:\mydir, in the MSYS shell to improve clarity, you would use cd /c/mydir though both c:\mydir and c:/mydir are supported.
  • The MSYS root directory is located in /c/mozilla-build/msys if you used the default installation directory. It's a good idea not to build anything under this directory. Instead use something like /c/mydir.

Common problems, hints, and restrictions

  • Debugging Mozilla on Windows FAQ: Tips on how to debug Mozilla on Windows.
  • If you have both Visual Studio 2015 and 2017 installed, the build system will default to using 2017. This can be overridden by adding the line below to your mozconfig file:
    ac_add_options --with-visual-studio-version=2015
  • The build may fail if your machine is configured with the wrong architecture. If you want to build 64-bit Firefox, add the two lines below to your mozconfig file:
    ac_add_options --target=x86_64-pc-mingw32
    ac_add_options --host=x86_64-pc-mingw32
  • The build may fail if your PATH environment variable contains quotes ("). Quotes are not properly translated when passed down to MozillaBuild sub-shells. Quotes are usually not needed so they can be removed.
  • The build may fail if you have a PYTHON environment variable set. It displays an error almost immediately that says "The system cannot find the file specified." In a command shell, typing "unset PYTHON" before running the Mozilla build tools in that same shell should fix this. Make sure that PYTHON is unset, rather than set to an empty value.
  • The build may fail if you have Cygwin installed. Make sure that the MozillaBuild directories (/c/mozilla-build and subdirectories) come before any Cygwin directories in your PATH environment variable. If this does not help, remove the Cygwin directories from PATH, or try building on a clean PC with no Cygwin.
  • Building with versions of NSIS other than the version that comes with the latest supported version of MozillaBuild is not supported and will likely fail.
  • If you intend to distribute your build to others, set WIN32_REDIST_DIR=$VCINSTALLDIR\redist\x86\Microsoft.VC80.CRT in your mozconfig to get the Microsoft CRT DLLs packaged along with the application.
  • The Microsoft Antimalware service can interfere with compilation, often manifesting as an error related to conftest.exe during build. To remedy this, add at least your object directory to the exclusion settings.
  • If you encounter an error like "second C linkage of overloaded function '_interlockedbittestandset' not allowed", it happens when intrin.h and windows.h are included together. Use a #define to redefine one instance of the function's name. See more on using intrin.h.
  • Parallel builds (-jN) do not work with GNU make on Windows. You should use the mozmake command included with current versions of MozillaBuild. Building with the mach command will always use the best available make command.

Return to the Build Documentation

文件標籤與貢獻者

 此頁面的貢獻者: tigercosmos
 最近更新: tigercosmos,