<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>proto/raze/patch/README.md - fork/rules_rust @ 0.6.0</title>
<meta name="description" content="proto/raze/patch/README.md in fork/rules_rust at 0.6.0.">
<meta property="og:title" content="proto/raze/patch/README.md - fork/rules_rust @ 0.6.0">
<meta property="og:description" content="proto/raze/patch/README.md in fork/rules_rust at 0.6.0.">
<meta property="og:type" content="website">
<meta property="og:site_name" content="git.julia.blue">
<link rel="stylesheet" href="/css/style.css?v=62">
<script type="module" src="/js/main.js?v=62"></script>
</head>
<body>
<main data-ref="0.6.0" data-tip="91466fc0d102b1754d39d0e9e2cffdb48e7671d0">
<noscript>
  <div class="callout">
    <p>
      hey! this is a static git repo viewer. commit diffs, file history,
      older commits and other revisions won't load without javascript.
    </p>
    <p>
      you are still able to view source files on branch/tag tips,
      but the experience is degraded.
    </p>
  </div>
</noscript>
<header class="repo"><div>
<h1>fork/rules_rust</h1>
</div>
<pre class="clone">git clone https://git.julia.blue/fork/rules_rust</pre>
</header>
<p class="snapshot-commit"><span class="commit-author">UebelAndre</span><span class="commit-message" data-commit="6f3a528c6dcfc4170a81c1366ba756495f4369a1">Regenerated proto raze outputs + addressed buildifier defects (#435)</span><span class="snapshot-sha sha" data-commit="6f3a528c6dcfc4170a81c1366ba756495f4369a1">6f3a528c</span><time datetime="2020-10-15T09:23:09-07:00" title="2020-10-15 09:23:09 -0700">2020-10-15</time></p>
<header class="topbar"><details class="switcher"><summary>0.6.0</summary><div class="menu"><strong>branches</strong><a href="/fork/rules_rust/ref/cleanup/">cleanup</a><a href="/fork/rules_rust/ref/gh-pages/">gh-pages</a><a href="/fork/rules_rust/ref/main/">main</a><a href="/fork/rules_rust/ref/patching/">patching</a><a href="/fork/rules_rust/ref/rust-analyzer/">rust-analyzer</a><strong>tags</strong><a href="/fork/rules_rust/ref/0.10.0/">0.10.0</a><a href="/fork/rules_rust/ref/0.11.0/">0.11.0</a><a href="/fork/rules_rust/ref/0.5.0/">0.5.0</a><a class="current" href="/fork/rules_rust/ref/0.6.0/">0.6.0</a><a href="/fork/rules_rust/ref/0.7.0/">0.7.0</a><a href="/fork/rules_rust/ref/0.8.0/">0.8.0</a><a href="/fork/rules_rust/ref/0.8.1/">0.8.1</a><a href="/fork/rules_rust/ref/0.9.0/">0.9.0</a><a class="all" href="/fork/rules_rust/refs">all refs →</a></div></details><nav class="crumbs"><a href="/fork/rules_rust/">rules_rust</a> / <a href="/fork/rules_rust/ref/0.6.0/tree/proto/">proto</a> / <a href="/fork/rules_rust/ref/0.6.0/tree/proto/raze/">raze</a> / <a href="/fork/rules_rust/ref/0.6.0/tree/proto/raze/patch/">patch</a> / <span class="cur">README.md</span></nav>
<span class="view-stats"><span>1.6 KiB</span><span>31 lines</span></span><span class="actions"><a class="raw" href="/fork/rules_rust/raw/2cd05d71a8cd382964363237ebce4ef90c2f6cd0/proto/raze/patch/README.md">raw</a></span></header>
<div class="markdown-view"><input type="radio" name="markdown-view" id="markdown-rendered" checked><label for="markdown-rendered">rendered</label><input type="radio" name="markdown-view" id="markdown-code"><label for="markdown-code">code</label><section class="readme rendered"><h1>Patches</h1>
<p>Cargo raze, in its remote mode allows for patches to be applied to a repository
before building it with rustc. It is advisable to use this functionality
sparingly, if at all. Also note that the patch is applied after all of the
dependency resolution has been completed by cargo raze, and that patching the
version of a dependency will not cause cargo raze to update that dependency in
the BUILD file.</p>
<p>The patch itself can be generated using git or another tool. The output of git
diff requires the <code>-p1</code> option to remove the leading <code>/</code> from the git diff patch
format.</p>
<h2>protobuf-2.8.2</h2>
<p>The protobuf crate from the rust-protobuf repository introduced a build.rs
script in the 2.x.x series. This generates a small version.rs file that would be
<a href="https://github.com/stepancheg/rust-protobuf/blob/v2.8/protobuf/src/lib.rs#L122">included into lib.rs</a>.
However, the build.rs file requires a number of environment variables, normally
provided by cargo to the build file. Cargo raze does not provide these
variables. The resulting code includes a version string and version identifier.
The version string is then used by protobuf-codegen to generate code refering to
the identifier in the protobuf library. The use can be seen
<a href="https://github.com/stepancheg/rust-protobuf/blob/v2.8/protobuf-codegen/src/lib.rs#L160">here</a>.
This is to enforce at compile time that the version of protobuf-codegen matches
the version of the protobuf crate.</p>
<p>For this crate, the patch that is applied is replacing the include! macro with
what would be generated by the build.rs file. This lets us avoid running the
build file altogether, at the expense of having to update the patch for every
version.</p>
</section><div class="code-panel"><pre class="code src language-markdown"><span class="code-line"><a class="ln" id="L1" href="#L1">1</a><span class="code-text"><a-p>#</a-p> <a-tt>Patches</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L2" href="#L2">2</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L3" href="#L3">3</a><span class="code-text">Cargo raze, in its remote mode allows for patches to be applied to a repository</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L4" href="#L4">4</a><span class="code-text">before building it with rustc. It is advisable to use this functionality</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L5" href="#L5">5</a><span class="code-text">sparingly, if at all. Also note that the patch is applied after all of the</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L6" href="#L6">6</a><span class="code-text">dependency resolution has been completed by cargo raze, and that patching the</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L7" href="#L7">7</a><span class="code-text">version of a dependency will not cause cargo raze to update that dependency in</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L8" href="#L8">8</a><span class="code-text">the BUILD file.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L9" href="#L9">9</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L10" href="#L10">10</a><span class="code-text">The patch itself can be generated using git or another tool. The output of git</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L11" href="#L11">11</a><span class="code-text">diff requires the `-p1` option to remove the leading `/` from the git diff patch</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L12" href="#L12">12</a><span class="code-text">format.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L13" href="#L13">13</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L14" href="#L14">14</a><span class="code-text"><a-p>##</a-p> <a-tt>protobuf-2.8.2</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L15" href="#L15">15</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L16" href="#L16">16</a><span class="code-text">The protobuf crate from the rust-protobuf repository introduced a build.rs</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L17" href="#L17">17</a><span class="code-text">script in the 2.x.x series. This generates a small version.rs file that would be</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L18" href="#L18">18</a><span class="code-text">[included into lib.rs](https://github.com/stepancheg/rust-protobuf/blob/v2.8/protobuf/src/lib.rs#L122).</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L19" href="#L19">19</a><span class="code-text">However, the build.rs file requires a number of environment variables, normally</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L20" href="#L20">20</a><span class="code-text">provided by cargo to the build file. Cargo raze does not provide these</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L21" href="#L21">21</a><span class="code-text">variables. The resulting code includes a version string and version identifier.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L22" href="#L22">22</a><span class="code-text">The version string is then used by protobuf-codegen to generate code refering to</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L23" href="#L23">23</a><span class="code-text">the identifier in the protobuf library. The use can be seen</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L24" href="#L24">24</a><span class="code-text">[here](https://github.com/stepancheg/rust-protobuf/blob/v2.8/protobuf-codegen/src/lib.rs#L160).</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L25" href="#L25">25</a><span class="code-text">This is to enforce at compile time that the version of protobuf-codegen matches</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L26" href="#L26">26</a><span class="code-text">the version of the protobuf crate.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L27" href="#L27">27</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L28" href="#L28">28</a><span class="code-text">For this crate, the patch that is applied is replacing the include! macro with</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L29" href="#L29">29</a><span class="code-text">what would be generated by the build.rs file. This lets us avoid running the</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L30" href="#L30">30</a><span class="code-text">build file altogether, at the expense of having to update the patch for every</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L31" href="#L31">31</a><span class="code-text">version.</span></span></pre></div></div>
</main>
</body>
</html>
