|
1 | 1 | # LibGit2Sharp.NativeBinaries
|
2 | 2 |
|
3 | 3 | **[Libgit2Sharp][lg2s]** is a managed wrapper around **[libgit2][lg2]**, and as
|
4 |
| -such requires compilation of libgit2 for your platform. |
| 4 | +such requires compilation of libgit2 for your platform. |
5 | 5 |
|
6 | 6 | LibGit2Sharp makes this easy by distributing, and leveraging as a dependency,
|
7 | 7 | the **[LibGit2Sharp.NativeBinaries][lg2s-nb]** NuGet package.
|
8 | 8 |
|
9 | 9 | This package contains the compiled versions of the libgit2 native library for
|
10 | 10 | the following platforms:
|
11 | 11 |
|
12 |
| - - Windows (x86/amd64) |
13 |
| - - Mac OS X (x86/amd64) |
14 |
| - - Linux (amd64) |
15 |
| - |
16 |
| -**Note:** Due to the large number of distributions, the Linux support is |
17 |
| -currently *experimental*. Would you encounter any issue with it, please open an |
18 |
| -**[issue][tracker]**. |
| 12 | + - Windows (x86, x64) |
| 13 | + - macOS (x64) |
| 14 | + - Linux (arm, arm64, x64) |
19 | 15 |
|
20 | 16 | [lg2s-nb]: https://www.nuget.org/packages/LibGit2Sharp.NativeBinaries
|
21 | 17 | [lg2]: https://libgit2.github.com/
|
22 | 18 | [lg2s]: http://libgit2sharp.com/
|
23 |
| - [tracker]: https://github.com/libgit2/libgit2sharp.nativebinaries/issues |
24 | 19 |
|
25 |
| -## How to build your own native binaries |
| 20 | +## Script overview |
26 | 21 |
|
27 |
| -If you need to build your own native binaries for some reason, you can |
28 |
| -do so easily with the scripts in this repository: |
| 22 | +The following scripts are used to build libgit2 and update this repo. |
29 | 23 |
|
30 |
| -1. Clone the `LibGit2Sharp.NativeBinaries` repository. Do so recursively |
31 |
| - to ensure that the `libgit2` submodule is initialized automatically: |
| 24 | +### build.libgit2.ps1 |
32 | 25 |
|
33 |
| - `git clone --recursive https://github.com/libgit2/libgit2sharp.nativebinaries` |
| 26 | +This script builds Windows libgit2 binaries. It requires Visual Studio 2019 to run. |
34 | 27 |
|
35 |
| - (If you have already cloned this repository (which seems quite |
36 |
| - likely since you are reading this file!) then you can simply run |
37 |
| - `git submodule init` followed by `git submodule update`.) |
| 28 | +To build x86 binaries: |
38 | 29 |
|
39 |
| -2. Update the included libgit2 sources and configuration files to the |
40 |
| - version of libgit2 you want to build. For example, to build |
41 |
| - commit `1a2b3c4`: |
| 30 | +``` |
| 31 | +build.libgit2.ps1 -x86 |
| 32 | +``` |
42 | 33 |
|
43 |
| - `UpdateLibgit2ToSha.ps1 1a2b3c4` |
| 34 | +To build x64 binaries: |
44 | 35 |
|
45 |
| - Or you can specify references. To build the remote's `master` branch: |
| 36 | +``` |
| 37 | +build.libgit2.ps1 -x64 |
| 38 | +``` |
46 | 39 |
|
47 |
| - `UpdateLibgit2ToSha.ps1 master` |
| 40 | +If both parameters are specified, both architectures will be built. See the script for additional parameters. |
48 | 41 |
|
49 |
| -3. Build the libgit2 binaries. For Windows, this requires a Visual Studio |
50 |
| - installation, and will compile both x86 and amd64 variants. (See |
51 |
| - "Notes on Visual Studio", below). Run the build PowerShell script, |
52 |
| - specifying the version number of Visual Studio as the first argument. |
53 |
| - For example, to build with Visual Studio 2013 (aka "Visual Studio 12.0"): |
| 42 | +### build.libgit2.sh |
54 | 43 |
|
55 |
| - `build.libgit2.ps1 12` |
| 44 | +This script builds Linux and macOS binaries. It can be invoked directly, but for Linux binaries, `dockerbuild.sh` should be used instead. |
56 | 45 |
|
57 |
| - For Linux, this will build only the architecture that you're running |
58 |
| - (x86 or amd64). For Mac OS X, this will build a fat library that |
59 |
| - includes both x86 and amd64. Run the shell script: |
| 46 | +### dockerbuild.sh |
60 | 47 |
|
61 |
| - `build.libgit2.sh` |
| 48 | +This script will build one of the Dockerfiles in the repo. It chooses which one to run based on the value of the `RID` environment variable. Using docker to build the Linux binaries for the various RIDs ensures that a specific environment and distro is used. |
62 | 49 |
|
63 |
| -4. Create the NuGet package from the built binaries. You will need to |
64 |
| - specify the version number of the resultant NuGet package that you |
65 |
| - want to generate. Note that you may wish to provide a suffix to |
66 |
| - disambiguate your custom package from the official, published NuGet |
67 |
| - packages. For example, if you are building a product called |
68 |
| - `fooproduct` then that may be a helpful suffix. |
| 50 | +### UpdateLibgit2ToSha.ps1 |
69 | 51 |
|
70 |
| - To build a NuGet package at version `1.2.3-foo`: |
| 52 | +This script is used to update the libgit2 submodule and update the references within the project to the correct libgit2 revision. |
71 | 53 |
|
72 |
| - `buildpackage.ps1 1.2.3-foo` |
| 54 | +You can update to a specific commit: |
73 | 55 |
|
74 |
| - And the result will be a NuGet package in the current directory: |
| 56 | +``` |
| 57 | +UpdateLibgit2ToSha.ps1 1a2b3c4 |
| 58 | +``` |
75 | 59 |
|
76 |
| - `LibGit2Sharp.NativeBinaries.1.2.3-foo.nupkg` |
| 60 | +Or you can specify references: |
77 | 61 |
|
78 |
| - Note that the `-foo` suffix technically makes this a "prerelease" |
79 |
| - package, according to NuGet, which may be further help in avoiding |
80 |
| - any mixups with the official packages, but may also require you to |
81 |
| - opt-in to prerelease packages in your NuGet package manager. |
| 62 | +``` |
| 63 | +UpdateLibgit2ToSha.ps1 master |
| 64 | +``` |
82 | 65 |
|
83 |
| -## Specifying custom DLL names |
| 66 | +## Building the package locally |
84 | 67 |
|
85 |
| -If you want to redistribute a LibGit2Sharp that uses a custom libgit2, |
86 |
| -you may want to change the name of the libgit2 shared library file to |
87 |
| -disambiguate it from other installations. This may be useful if you |
88 |
| -are running as a plugin inside a larger process and wish to avoid |
89 |
| -conflicting with other plugins who may wish to use LibGit2Sharp and |
90 |
| -want to ensure that *your* version of libgit2 is loaded into memory |
91 |
| -and available to you. |
| 68 | +After running the appropriate build script(s) to create binaries, the NuGet package needs to be created. |
92 | 69 |
|
93 |
| -For example, if your plugin names if `fooplugin`, you may wish to |
94 |
| -distribute a DLL named `git2-fooplugin.dll`. You can specify the |
95 |
| -custom DLL name as the second argument to the update and build scripts: |
| 70 | +First, to use the same version locally that will be generated via CI, install the [minver-cli](https://www.nuget.org/packages/minver-cli) dotnet tool: |
96 | 71 |
|
97 |
| - UpdateLibgit2ToSha.ps1 1a2b3c4 git2-fooplugin |
98 |
| - build.libgit2.sh 14 git2-fooplugin |
| 72 | +``` |
| 73 | +dotnet tool install --global minver-cli |
| 74 | +``` |
99 | 75 |
|
100 |
| -Then build the NuGet package as described above, making sure to provide |
101 |
| -a helpful suffix to ensure that your NuGet package will not be confused |
102 |
| -with the official packages. |
| 76 | +Once that is installed, running the `minver` command will output a version: |
103 | 77 |
|
104 |
| -### Notes on Visual Studio |
| 78 | +``` |
| 79 | +MinVer: Using { Commit: 2453a6d, Tag: '2.0.312', Version: 2.0.312, Height: 3 }. |
| 80 | +MinVer: Calculated version 2.0.313-alpha.0.3. |
| 81 | +2.0.313-alpha.0.3 |
| 82 | +``` |
105 | 83 |
|
106 |
| -Visual Studio is required to build the native binaries, however you |
107 |
| -do not need to install a *paid* version of Visual Studio. libgit2 |
108 |
| -can be compiled using [Visual Studio Community](https://www.visualstudio.com/en-us/products/visual-studio-community-vs), |
109 |
| -which is free for building open source applications. |
| 84 | +To create the package, use the the following command: |
| 85 | + |
| 86 | +``` |
| 87 | +nuget.exe Pack nuget.package/NativeBinaries.nuspec -Version <version> -NoPackageAnalysis |
| 88 | +``` |
| 89 | + |
| 90 | +Where `<version>` is the version from the MinVer tool or manually chosen version. |
110 | 91 |
|
111 |
| -You need to specify the actual version number (not the marketing name) |
112 |
| -of Visual Studio. (For example, "Visual Studio 2013" is the name of the |
113 |
| -product, but its actual version number is "12.0".) A handy guide: |
114 |
| - |
115 |
| -| Marketing Name | Version Number |
116 |
| -|--------------------|--------------- |
117 |
| -| Visual Studio 2010 | 10 |
118 |
| -| Visual Studio 2012 | 11 |
119 |
| -| Visual Studio 2013 | 12 |
120 |
| -| Visual Studio 2015 | 14 |
121 |
| -| Visual Studio 2017 | 15 |
| 92 | + |
| 93 | +## Notes on Visual Studio |
| 94 | + |
| 95 | +Visual Studio 2019 is required to build the Windows native binaries, however you |
| 96 | +do not need to install a *paid* version of Visual Studio. libgit2 |
| 97 | +can be compiled using [Visual Studio Community](https://visualstudio.microsoft.com/vs/community/), |
| 98 | +which is free for building open source applications. |
0 commit comments