Skip to content

Instantly share code, notes, and snippets.

@ChunMinChang
Last active February 28, 2024 18:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChunMinChang/bd39852e96f39fce328de812e64a5b3c to your computer and use it in GitHub Desktop.
Save ChunMinChang/bd39852e96f39fce328de812e64a5b3c to your computer and use it in GitHub Desktop.
Building gecko

Building Firefox on Linux

  1. Check if git is installed in your system
  2. Open terminal
    # Clone your own gecko repository
    git clone https://github.com/<your_username>/gecko-dev.git
    
    # e.g., git clone https://github.com/ChunMinChang/gecko-dev.git
    # or use mozilla's repo directly by git clone https://github.com/mozilla/gecko-dev.git
    
    # If you use your own gecko repo, set mozilla's repo as upstream and update your repo
    # (This step is not necessary)
    cd gecko-dev/
    git remote add upstream https://github.com/mozilla/gecko-dev.git
    git fetch upstream
    git merge --ff-only upstream/master
    git push
    
    # Install necessary utils for building gecko,
    # including the git-cinnabar at c:/Users/Chun-Min Chang/.mozbuild\git-cinnabar
    ./mach bootstrap
    
    # Install moz-phab to submit patches
    mach install-moz-phab
    
    # Export git-cinnabar to PATH
    export PATH="$HOME/.mozbuild/git-cinnabar:$PATH"
    
    # Then, follow https://github.com/glandium/git-cinnabar/wiki/Mozilla:-A-git-workflow-for-Gecko-development
    # to setup the remotes.
    # 1. Add remotes for the mercurial repositories you pull from
    git config fetch.prune true
    git remote add central hg::https://hg.mozilla.org/mozilla-central -t branches/default/tip
    git config remote.central.fetch +refs/heads/branches/default/tip:refs/remotes/central/default
    
    # 2. Setup a remote for the try server
    git remote add try hg::https://hg.mozilla.org/try
    git config remote.try.skipDefaultUpdate true
    git remote set-url --push try hg::ssh://hg.mozilla.org/try
    git config remote.try.push +HEAD:refs/heads/branches/default/tip
    
    # 3. Update all the remotes (probably needs 1 hour)
    git remote update
    
    # Now mozilla-central is cloned and up to date. you can start developing from central branch
    
    # Create a central branch
    git checkout -b central central/default

Building Firefox on Windows

The following steps will setup an environment to develop gecko with git via git-cinnabar

  1. Install Git for Windows, which will install git at /c/Program Files/Git/

  2. Follow steps here to install Visual Studio

  3. Follow steps here to install MozillaBuild, which will install the things needed to build gecko at c:\mozilla-build\, including a terminal at c:\mozilla-build\start-shell.bat

    • Creating a shortcut to c:\mozilla-build\start-shell.bat on the desktop
  4. Open the start-shell installed in above step and run following commands:

    # Export git to PATH
    # PATH="$PATH:/c/Program Files/Git/bin" # Need to match to step 1
    
    # Clone your own gecko repository
    git clone https://github.com/<your_username>/gecko-dev.git
    # e.g., git clone https://github.com/ChunMinChang/gecko-dev.git
    # or use mozilla's repo directly by
    # git clone https://github.com/mozilla/gecko-dev.git
    
    # If you use your own gecko repo, set mozilla's repo as upstream and update your repo
    # (This step is not necessary)
    cd gecko-dev/
    git remote add upstream https://github.com/mozilla/gecko-dev.git
    git fetch upstream
    git merge --ff-only upstream/master
    git push
    
    # Install necessary utils for building gecko,
    # including the git-cinnabar at c:/Users/Chun-Min Chang/.mozbuild\git-cinnabar
    ./mach bootstrap
    
    # Install moz-phab to submit patches
    mach install-moz-phab
    
    # Export git-cinnabar to PATH
    export PATH="$HOME/.mozbuild\git-cinnabar:$PATH"
    # !!! Please note that the username cannot have space ' ' !!!
    # otherwise cinnabar won't be a valid git subcommand (it's better not to have dash '-' either)
    # (X) export PATH="c:/Users/Chun-Min Chang/.mozbuild\git-cinnabar:$PATH"
    # (O) export PATH="c:/Users/CM/.mozbuild\git-cinnabar:$PATH"
    
    # Turn off auto line ending for Unix style on Windows
    # the default value can be shown by running: git config --list
    git config core.autocrlf false
    
    # Then, follow https://github.com/glandium/git-cinnabar/wiki/Mozilla:-A-git-workflow-for-Gecko-development
    # to setup the remotes.
    # The following remote url are modified to fit the Windows format:
    # https://github.com/glandium/git-cinnabar/wiki/Windows-Support
    # 1. Add remotes for the mercurial repositories you pull from
    git config fetch.prune true
    git remote add central hg://hg.mozilla.org/mozilla-central -t branches/default/tip
    git config remote.central.fetch +refs/heads/branches/default/tip:refs/remotes/central/default
    
    # 2. Setup a remote for the try server
    git remote add try hg://hg.mozilla.org/try
    git config remote.try.skipDefaultUpdate true
    git remote set-url --push try hg://hg.mozilla.org:ssh/try
    
    # 3. Update all the remotes (probably needs 1 hour)
    git remote update
    
    # Now mozilla-central is cloned and up to date. you can start developing from central branch
    
    # Create a central branch
    git checkout -b central central/default
    
    # or create your branch based on central to fix bug N
    git checkout -b bug-N central/default
  5. It's better to add git-cinnabar to PATH in start-shell so you don't need to export git-cinnabar to $PATH every time. Add SET "PATH=%PATH%;%homepath%/.mozbuild\git-cinnabar" above REM Start shell. should work. You can check by calling echo $PATH in start-shell to see if git-cinnabar is set in $PATH

SSH

ssh must be setup to push a commit to try server

  1. If you don't have ssh keys to access Mozilla's server, follow here to request one

  2. If you already have ssh keys, open the start-shell and copy id_rsa and id_rsa.pub to $HOME/.ssh/ by cp ~/<path>/<to>/<ssh>/id_rsa* ~/.ssh/

  3. Go to cd ~/.ssh

  4. run eval "$(ssh-agent -s)"

  5. Register your ssh key to this device by ssh-add ~/.ssh/id_rsa

  6. Add the following to $HOME/.ssh/config (or create a $HOME/.ssh/config if you don't have one)

    Host hg.mozilla.org
    User <your_email>
    IdentityFile ~/.ssh/id_rsa
    
  7. Run ssh -v hg.mozilla.org to test if the access works

    • You may see a message like: A SSH connection has been successfully established.
  8. Set GIT_SSH by export GIT_SSH=/bin/ssh

  9. Go back to your gecko repository and try running ./mach try chooser

  10. It's better to add GIT_SSH in start-shell so you don't need to set GIT_SSH everytime. Add SET "GIT_SSH=/bin/ssh" under IF DEFINED GITDIR should work. You can check by calling echo $GIT_SSH in start-shell to see if $GIT_SSH is set

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment