|
| 1 | +### Contributing to core functionality or base libraries |
| 2 | + |
| 3 | +*By contributing code to Julia, you are agreeing to release it under the [MIT License](https://github.com/JuliaLang/julia/tree/master/LICENSE.md).* |
| 4 | + |
| 5 | +The Julia community uses [GitHub issues](https://github.com/JuliaLang/julia/issues) to track and discuss problems, feature requests, and pull requests (PR). |
| 6 | + |
| 7 | +Issues and pull requests should have self explanatory titles such that they can be understood from the list of PRs and Issues. |
| 8 | +i.e. `Add {feature}` and `Fix {bug}` are good, `Fix #12345. Corrects the bug.` is bad. |
| 9 | + |
| 10 | +You can make pull requests for incomplete features to get code review. The convention is to open these as draft PRs and prefix |
| 11 | +the pull request title with "WIP:" for Work In Progress, or "RFC:" for Request for Comments when work is completed and ready |
| 12 | +for merging. This will prevent accidental merging of work that is in progress. |
| 13 | + |
| 14 | +Note: These instructions are for adding to or improving functionality in the base library. Before getting started, it can be helpful to discuss the proposed changes or additions on the [Julia Discourse forum](https://discourse.julialang.org) or in a GitHub issue---it's possible your proposed change belongs in a package rather than the core language. Also, keep in mind that changing stuff in the base can potentially break a lot of things. Finally, because of the time required to build Julia, note that it's usually faster to develop your code in stand-alone files, get it working, and then migrate it into the base libraries. |
| 15 | + |
| 16 | +Add new code to Julia's base libraries as follows (this is the "basic" approach; see a more efficient approach in the next section): |
| 17 | + |
| 18 | + 1. Edit the appropriate file in the `base/` directory, or add new files if necessary. Create tests for your functionality and add them to files in the `test/` directory. If you're editing C or Scheme code, most likely it lives in `src/` or one of its subdirectories, although some aspects of Julia's REPL initialization live in `cli/`. |
| 19 | + |
| 20 | + 2. Add any new files to `sysimg.jl` in order to build them into the Julia system image. |
| 21 | + |
| 22 | + 3. Add any necessary export symbols in `exports.jl`. |
| 23 | + |
| 24 | + 4. Include your tests in `test/Makefile` and `test/choosetests.jl`. |
| 25 | + |
| 26 | +Build as usual, and do `make clean testall` to test your contribution. If your contribution includes changes to Makefiles or external dependencies, make sure you can build Julia from a clean tree using `git clean -fdx` or equivalent (be careful – this command will delete any files lying around that aren't checked into git). |
| 27 | + |
| 28 | +#### Running specific tests |
| 29 | + |
| 30 | +There are `make` targets for running specific tests: |
| 31 | + |
| 32 | + make test-bitarray |
| 33 | + |
| 34 | +You can also use the `runtests.jl` script, e.g. to run `test/bitarray.jl` and `test/math.jl`: |
| 35 | + |
| 36 | + ./usr/bin/julia test/runtests.jl bitarray math |
| 37 | + |
| 38 | +#### Modifying base more efficiently with Revise.jl |
| 39 | + |
| 40 | +[Revise](https://github.com/timholy/Revise.jl) is a package that |
| 41 | +tracks changes in source files and automatically updates function |
| 42 | +definitions in your running Julia session. Using it, you can make |
| 43 | +extensive changes to Base without needing to rebuild in order to test |
| 44 | +your changes. |
| 45 | + |
| 46 | +Here is the standard procedure: |
| 47 | + |
| 48 | +1. If you are planning changes to any types or macros, make those |
| 49 | + changes and build julia using `make`. (This is |
| 50 | + necessary because `Revise` cannot handle changes to type |
| 51 | + definitions or macros.) Unless it's |
| 52 | + required to get Julia to build, you do not have to add any |
| 53 | + functionality based on the new types, just the type definitions |
| 54 | + themselves. |
| 55 | + |
| 56 | +2. Start a Julia REPL session. Then issue the following commands: |
| 57 | + |
| 58 | +```julia |
| 59 | +using Revise # if you aren't launching it in your `.julia/config/startup.jl` |
| 60 | +Revise.track(Base) |
| 61 | +``` |
| 62 | + |
| 63 | +3. Edit files in `base/`, save your edits, and test the |
| 64 | + functionality. |
| 65 | + |
| 66 | +If you need to restart your Julia session, just start at step 2 above. |
| 67 | +`Revise.track(Base)` will note any changes from when Julia was last |
| 68 | +built and incorporate them automatically. You only need to rebuild |
| 69 | +Julia if you made code-changes that Revise cannot handle. |
| 70 | + |
| 71 | +For convenience, there are also `test-revise-*` targets for every [`test-*` |
| 72 | +target](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md#running-specific-tests) that use Revise to load any modifications to Base into the current |
| 73 | +system image before running the corresponding test. This can be useful as a shortcut |
| 74 | +on the command line (since tests aren't always designed to be run outside the |
| 75 | +runtest harness). |
| 76 | + |
| 77 | +### Contributing to the standard library |
| 78 | + |
| 79 | +The standard library (stdlib) packages are baked into the Julia system image. |
| 80 | +When running the ordinary test workflow on the stdlib packages, the system image |
| 81 | +version overrides the version you are developing. |
| 82 | +To test stdlib packages, you can do the following steps: |
| 83 | + |
| 84 | +1. Edit the UUID field of the `Project.toml` in the stdlib package |
| 85 | +2. Change the current directory to the directory of the stdlib you are developing |
| 86 | +3. Start julia with `julia --project=.` |
| 87 | +4. You can now test the package by running `pkg> test` in Pkg mode. |
| 88 | + |
| 89 | +Because you changed the UUID, the package manager treats the stdlib package as |
| 90 | +different from the one in the system image, and the system image version will |
| 91 | +not override the package. |
| 92 | + |
| 93 | +Be sure to change the UUID value back before making the pull request. |
| 94 | + |
| 95 | +#### News-worthy changes |
| 96 | + |
| 97 | +For new functionality and other substantial changes, add a brief summary to `NEWS.md`. The news item should cross reference the pull request (PR) parenthetically, in the form `([#pr])`. To add the PR reference number, first create the PR, then push an additional commit updating `NEWS.md` with the PR reference number. We periodically run `./julia doc/NEWS-update.jl` from the julia directory to update the cross-reference links, but this should not be done in a typical PR in order to avoid conflicting commits. |
| 98 | + |
| 99 | +#### Annotations for new features, deprecations and behavior changes |
| 100 | + |
| 101 | +API additions and deprecations, and minor behavior changes are allowed in minor version releases. |
| 102 | +For documented features that are part of the public API, a compatibility note should be added into |
| 103 | +the manual or the docstring. It should state the Julia minor version that changed the behavior |
| 104 | +and have a brief message describing the change. |
| 105 | + |
| 106 | +At the moment, this should always be done with the following `compat` admonition |
| 107 | +(so that it would be possible to programmatically find the annotations in the future): |
| 108 | + |
| 109 | + ``` |
| 110 | + !!! compat "Julia 1.X" |
| 111 | + This method was added in Julia 1.X. |
| 112 | + ``` |
0 commit comments