How to Build Firefox

By  on  

Firefox Nightly Open source is a dream and a gateway to an amazing career -- I'm a testament to that. One of the most amazing open source projects to ever exist, Mozilla Firefox, is a project I'm proud to work on as an employee of Mozilla. It's rewarding, challenging, and a unique experience...and I want you to join me!

Take a few moments with me to learn how to build the amazing Firefox!

Step 1: Clone Mozilla Central

Mozilla Central is the name of the mercurial repository that contains the source code of Firefox. Start by installing mercurial and cloning "MC":

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

hg clone {repo_url} is the first and most basic mercurial command, but check out my Mercurial Productivity Tips post to learn more hg commands! "MC" will be installed in a mozilla-central directory.

Step 2: Install Dependencies

From C++ to Rust, Firefox has a fair bit of requirements you'll need to install. From within the mozilla-central directory, run the following:

./mach bootstrap

The bootstrap command will install dependencies as well as configure mercurial extensions as required. Congratulations -- you're now ready to build!

Step 3: Create a mozconfig

You'll thank me for this one! Create a mozconfig file to use artifact builds, which will save loads of time during the build process by downloading pre-built binaries for Firefox's internals.

# Automatically download and use compiled C++ components:
ac_add_options --enable-artifact-builds

# Write build artifacts to:
mk_add_options MOZ_OBJDIR=./objdir-frontend

Place the code above in your mozconfig file and you're builds will be super fast!

Step 4: Build!

Once you have the code and the dependencies, it's time to build the amazing Firefox! You can build Firefox with the following command:

./mach build

Hello Firefox!

Step 5: Run Firefox

Once you've built the amazing Firefox, you can run Firefox with the following mach command:

./mach run --jsdebugger

Congratulations! You've taken the Firefox source code and turned it into an application that you can run! The --jsdebugger option opens the "browser toolbox" which allows you to debug the Firefox you've just built.

Updating Mozilla Central Code

The Mozilla Central repository is updated several times a day as Mozilla employees and contributors like you submit patches. You can update your local checkout with the following:

hg pull && hg update --clean

You local commits will always be draft status while patches which have been merged into MC will be public status.

Configuring Options

Whenever Firefox developer and the community develop new features, they're hidden behind a preference until the feature reaches maturity. To toggle feature flags, you can visit about:config in your local Firefox or any Firefox release.

about:config

The config page allows you to toggle and set a number of options. Many "edge" features debut behind feature flags in Firefox Nightly.

Congratulations! You've turned a massive repository of code into a living, breathing Firefox web browser! In the next post in the Firefox series, we'll explore contribution and testing!

Recent Features

  • By
    5 Awesome New Mozilla Technologies You’ve Never Heard Of

    My trip to Mozilla Summit 2013 was incredible.  I've spent so much time focusing on my project that I had lost sight of all of the great work Mozillians were putting out.  MozSummit provided the perfect reminder of how brilliant my colleagues are and how much...

  • By
    Camera and Video Control with HTML5

    Client-side APIs on mobile and desktop devices are quickly providing the same APIs.  Of course our mobile devices got access to some of these APIs first, but those APIs are slowly making their way to the desktop.  One of those APIs is the getUserMedia API...

Incredible Demos

Discussion

  1. Jørgen Østensen

    Could you say something how to build support for gpsd? I have application that are made with javascript dependent on GPS for use in a sail boat. I need to compile Firefox with support for gpsd. I plan to use the browser with raspberry pi and Linux.

  2. Sandeep

    Hi, While trying to build. I am getting this error. I am new to building from source code.

    I have following error:

     0:04.72 checking whether the C compiler supports -Wformat-overflow=2... yes
     0:04.76 checking whether the C++ compiler supports -Wformat-overflow=2... yes
     0:04.80 checking whether the C compiler supports -Wno-gnu-zero-variadic-macro-arguments... no
     0:04.82 checking whether the C++ compiler supports -Wno-gnu-zero-variadic-macro-arguments... no
     0:04.87 checking whether the C++ compiler supports -fno-sized-deallocation... yes
     0:04.91 checking whether the C++ compiler supports -fno-aligned-new... yes
     0:04.93 checking for libpulse... yes
     0:04.94 checking MOZ_PULSEAUDIO_CFLAGS... -D_REENTRANT
     0:04.95 checking MOZ_PULSEAUDIO_LIBS... -lpulse
     0:04.95 checking for rustc... not found
     0:04.95 checking for cargo... not found
     0:04.95 Traceback (most recent call last):
     0:04.95   File "/home/panda/mozilla-central/configure.py", line 164, in <module>
     0:04.95     sys.exit(main(sys.argv))
     0:04.95   File "/home/panda/mozilla-central/configure.py", line 40, in main
     0:04.95     sandbox.run(os.path.join(os.path.dirname(__file__), 'moz.configure'))
     0:04.95   File "/home/panda/mozilla-central/python/mozbuild/mozbuild/configure/__init__.py", line 499, in run
     0:04.96     func(*args)
     0:04.96   File "/home/panda/mozilla-central/python/mozbuild/mozbuild/configure/__init__.py", line 543, in _value_for
     0:04.96     return self._value_for_depends(obj)
     0:04.96   File "/home/panda/mozilla-central/python/mozbuild/mozbuild/util.py", line 963, in method_call
     0:04.96     cache[args] = self.func(instance, *args)
     0:04.96   File "/home/panda/mozilla-central/python/mozbuild/mozbuild/configure/__init__.py", line 552, in _value_for_depends
     0:04.96     value = obj.result()
     0:04.96   File "/home/panda/mozilla-central/python/mozbuild/mozbuild/util.py", line 963, in method_call
     0:04.96     cache[args] = self.func(instance, *args)
     0:04.96   File "/home/panda/mozilla-central/python/mozbuild/mozbuild/configure/__init__.py", line 155, in result
     0:04.96     return self._func(*resolved_args)
     0:04.96   File "/home/panda/mozilla-central/python/mozbuild/mozbuild/configure/__init__.py", line 1152, in wrapped
     0:04.96     return new_func(*args, **kwargs)
     0:04.96   File "/home/panda/mozilla-central/build/moz.configure/rust.configure", line 59, in unwrap
     0:04.96     (retcode, stdout, stderr) = get_cmd_output(prog, '+stable')
     0:04.96   File "/home/panda/mozilla-central/python/mozbuild/mozbuild/configure/__init__.py", line 1152, in wrapped
     0:04.96     return new_func(*args, **kwargs)
     0:04.96   File "/home/panda/mozilla-central/build/moz.configure/util.configure", line 30, in get_cmd_output
     0:04.96     log.debug('Executing: %s', quote(*args))
     0:04.96   File "/home/panda/mozilla-central/python/mozbuild/mozbuild/shellutil.py", line 210, in quote
     0:04.96     return ' '.join(_quote(s) for s in strings)
     0:04.96   File "/home/panda/mozilla-central/python/mozbuild/mozbuild/shellutil.py", line 210, in <genexpr>
     0:04.96     return ' '.join(_quote(s) for s in strings)
     0:04.96   File "/home/panda/mozilla-central/python/mozbuild/mozbuild/shellutil.py", line 198, in _quote
     0:04.96     return t("'%s'") % s.replace(t("'"), t("'\\''"))
     0:04.96 TypeError: cannot create 'NoneType' instances
     0:05.02 *** Fix above errors and then restart with\
     0:05.02                "./mach build"
     0:05.02 client.mk:111: recipe for target 'configure' failed
     0:05.02 make: *** [configure] Error 1
    

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!