2016-03-30 23:15:15 +02:00
|
|
|
Build PowerShell on Linux
|
|
|
|
=========================
|
|
|
|
|
2016-07-18 21:29:17 +02:00
|
|
|
This guide will walk you through building PowerShell on Linux.
|
|
|
|
We'll start by showing how to set up your environment from scratch.
|
2016-03-30 23:15:15 +02:00
|
|
|
|
|
|
|
Environment
|
|
|
|
===========
|
|
|
|
|
2016-07-18 21:29:17 +02:00
|
|
|
These instructions are written assuming the Ubuntu 14.04 LTS, since that's the distro the team uses.
|
|
|
|
The build module works on a best-effort basis for other distributions.
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2016-04-14 01:21:23 +02:00
|
|
|
Git Setup
|
|
|
|
---------
|
|
|
|
|
2016-07-18 21:29:17 +02:00
|
|
|
Using Git requires it to be set up correctly;
|
2016-08-07 00:53:51 +02:00
|
|
|
refer to the [Working with the PowerShell Repository](../git/README.md),
|
2016-07-18 21:29:17 +02:00
|
|
|
[README](../../README.md), and [Contributing Guidelines](../../.github/CONTRIBUTING.md).
|
2016-04-14 01:21:23 +02:00
|
|
|
|
2016-07-18 21:29:17 +02:00
|
|
|
**This guide assumes that you have recursively cloned the PowerShell repository and `cd`ed into it.**
|
2016-04-14 01:21:23 +02:00
|
|
|
|
2016-03-30 23:15:15 +02:00
|
|
|
Toolchain Setup
|
|
|
|
---------------
|
|
|
|
|
2016-07-18 21:29:17 +02:00
|
|
|
We use the [.NET Command-Line Interface][dotnet-cli] (`dotnet`) to build the managed components,
|
|
|
|
and [CMake][] to build the native components.
|
|
|
|
Install the following packages for the toolchain:
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2016-07-16 03:34:33 +02:00
|
|
|
- `dotnet`: Must be installed from the `Start-PSBootstrap` module as described below.
|
2016-03-30 23:15:15 +02:00
|
|
|
- `cmake`
|
|
|
|
- `make`
|
|
|
|
- `g++`
|
|
|
|
|
2016-04-05 03:52:54 +02:00
|
|
|
Unfortunately, the `apt-get` feed for `dotnet` has been deprecated,
|
2016-07-18 21:29:17 +02:00
|
|
|
and the latest version is only distributed in the form of three separate packages,
|
|
|
|
which require manual dependency resolution.
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2016-07-18 21:29:17 +02:00
|
|
|
Installing the toolchain is as easy as running `Start-PSBootstrap` in PowerShell.
|
|
|
|
Of course, this requires a self-hosted copy of PowerShell on Linux.
|
2016-04-14 01:21:23 +02:00
|
|
|
|
2016-08-19 18:09:12 +02:00
|
|
|
Fortunately, this is as easy as [downloading and installing the package](../installation/linux.md).
|
2016-06-06 21:05:27 +02:00
|
|
|
The `./tools/download.sh` script will also install the PowerShell package.
|
2016-04-14 01:21:23 +02:00
|
|
|
|
|
|
|
In Bash:
|
|
|
|
|
2016-07-16 03:34:33 +02:00
|
|
|
```sh
|
|
|
|
./tools/download.sh
|
|
|
|
|
2016-04-14 01:21:23 +02:00
|
|
|
powershell
|
|
|
|
```
|
|
|
|
|
2016-07-18 21:29:17 +02:00
|
|
|
You should now be in a `powershell` console host that is installed separately from any development copy you're about to build.
|
|
|
|
Just import our module, bootstrap the dependencies, and build!
|
2016-07-16 03:34:33 +02:00
|
|
|
|
2016-04-14 01:21:23 +02:00
|
|
|
In PowerShell:
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2016-04-14 01:21:23 +02:00
|
|
|
```powershell
|
2016-05-18 22:58:59 +02:00
|
|
|
Import-Module ./build.psm1
|
2016-04-14 01:21:23 +02:00
|
|
|
Start-PSBootstrap
|
|
|
|
```
|
|
|
|
|
|
|
|
The `Start-PSBootstrap` function does the following:
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2016-04-05 03:52:54 +02:00
|
|
|
- Adds the LLVM package feed
|
2016-07-18 21:29:17 +02:00
|
|
|
- Installs our dependencies combined with the dependencies of the .NET CLI toolchain via `apt-get`
|
2016-06-11 01:06:08 +02:00
|
|
|
- Uninstalls any prior versions of .NET CLI
|
2016-08-19 18:09:12 +02:00
|
|
|
- Downloads and installs the latest .NET CLI 1.0.0-preview3 SDK to `~/.dotnet`
|
2016-06-11 01:06:08 +02:00
|
|
|
|
2016-07-18 21:29:17 +02:00
|
|
|
If you want to use `dotnet` outside of `Start-PSBuild`, add `~/.dotnet` to your `PATH` environment variable.
|
2016-03-30 23:15:15 +02:00
|
|
|
|
|
|
|
[dotnet-cli]: https://github.com/dotnet/cli#new-to-net-cli
|
|
|
|
[CMake]: https://cmake.org/cmake/help/v2.8.12/cmake.html
|
|
|
|
|
|
|
|
.NET CLI
|
|
|
|
--------
|
|
|
|
|
2016-07-18 21:29:17 +02:00
|
|
|
If you have any problems installing `dotnet`, please see their [documentation][cli-docs].
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2016-07-18 21:29:17 +02:00
|
|
|
The version of .NET CLI is very important; you need a recent build of 1.0.0 (**not** 1.0.1).
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2016-07-18 21:29:17 +02:00
|
|
|
Previous installations of DNX, `dnvm`, or older installations of .NET CLI can cause odd failures when running.
|
|
|
|
Please check your version and uninstall prior any prior versions.
|
2016-03-30 23:15:15 +02:00
|
|
|
|
|
|
|
[cli-docs]: https://dotnet.github.io/getting-started/
|
|
|
|
|
|
|
|
Build using our module
|
|
|
|
======================
|
|
|
|
|
2016-07-18 21:29:17 +02:00
|
|
|
We maintain a [PowerShell module](../../build.psm1) with the function `Start-PSBuild` to build PowerShell.
|
|
|
|
Since this is PowerShell code, it requires self-hosting.
|
|
|
|
If you have followed the toolchain setup section above, you should have `powershell` installed.
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2016-04-05 03:52:54 +02:00
|
|
|
> If you cannot or do not want to self-host, `Start-PSBuild` is just a
|
|
|
|
> convenience; you can execute each step of the build process yourself
|
2016-09-06 06:55:09 +02:00
|
|
|
> in Bash; see [Build manually](#build-manually) below.
|
2016-04-05 03:52:54 +02:00
|
|
|
|
2016-03-30 23:15:15 +02:00
|
|
|
```powershell
|
2016-05-18 22:58:59 +02:00
|
|
|
Import-Module ./build.psm1
|
2016-03-30 23:15:15 +02:00
|
|
|
Start-PSBuild
|
|
|
|
```
|
2016-04-05 03:52:54 +02:00
|
|
|
Congratulations! If everything went right, PowerShell is now built.
|
|
|
|
The `Start-PSBuild` script will output the location of the executable:
|
2016-07-16 03:34:33 +02:00
|
|
|
|
2016-08-02 21:45:21 +02:00
|
|
|
`./src/powershell-unix/bin/Linux/netcoreapp1.0/ubuntu.14.04-x64/powershell`.
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2016-07-18 21:29:17 +02:00
|
|
|
You should now be running the `powershell` that you just built, if your run the above executable.
|
|
|
|
You can run our cross-platform Pester tests with `Start-PSPester`, and our xUnit tests with `Start-PSxUnit`.
|
2016-03-30 23:15:15 +02:00
|
|
|
|
|
|
|
Build manually
|
|
|
|
==============
|
|
|
|
|
|
|
|
The following goes into detail about what `Start-PSBuild` does.
|
|
|
|
|
2016-10-18 00:21:57 +02:00
|
|
|
There are two preliminary steps that apply to all operating systems,
|
|
|
|
the [ResGen](internals.md#resgen) and [type catalog generation](internals.md#type-catalog),
|
|
|
|
documented in [internals of build process](internals.md#preliminary-steps).
|
|
|
|
|
2016-03-30 23:15:15 +02:00
|
|
|
Build the native library
|
|
|
|
------------------------
|
|
|
|
|
2016-07-18 21:29:17 +02:00
|
|
|
The `libpsl-native.so` library consists of native functions that `CorePsPlatform.cs` P/Invokes.
|
2016-03-30 23:15:15 +02:00
|
|
|
|
|
|
|
```sh
|
|
|
|
pushd src/libpsl-native
|
|
|
|
cmake -DCMAKE_BUILD_TYPE=Debug .
|
|
|
|
make -j
|
|
|
|
make test
|
|
|
|
popd
|
|
|
|
```
|
|
|
|
|
2016-08-02 21:45:21 +02:00
|
|
|
This library will be emitted in the `src/powershell-unix` project,
|
2016-07-18 21:29:17 +02:00
|
|
|
where `dotnet` consumes it as "content" and thus automatically deploys it.
|
2016-03-30 23:15:15 +02:00
|
|
|
|
|
|
|
Build the managed projects
|
|
|
|
--------------------------
|
|
|
|
|
2016-07-18 21:29:17 +02:00
|
|
|
The `powershell` project is the .NET Core PowerShell host.
|
|
|
|
It is the top level project, so `dotnet build` transitively builds all its dependencies, and emits a `powershell` executable.
|
|
|
|
The `--configuration Linux` flag is necessary to ensure that the preprocessor definition `LINUX` is defined (see [issue #673][]).
|
2016-03-30 23:15:15 +02:00
|
|
|
|
|
|
|
```sh
|
|
|
|
dotnet restore
|
2016-08-02 21:45:21 +02:00
|
|
|
cd src/powershell-unix
|
2016-04-05 03:52:54 +02:00
|
|
|
dotnet build --configuration Linux
|
2016-03-30 23:15:15 +02:00
|
|
|
```
|
|
|
|
|
2016-07-18 21:29:17 +02:00
|
|
|
The executable will be in `./bin/[configuration]/[framework]/[rid]/[binary name]`,
|
|
|
|
where our configuration is `Linux`, framework is `netcoreapp1.0`,
|
|
|
|
runtime identifier is `ubuntu.14.04-x64`, and binary name is `powershell`.
|
|
|
|
The function `Get-PSOutput` will return the path to the executable;
|
|
|
|
thus you can execute the development copy via `& (Get-PSOutput)`.
|
|
|
|
|
|
|
|
For deploying PowerShell, `dotnet publish` will emit a `publish` directory that contains a flat list of every dependency required for
|
|
|
|
PowerShell.
|
|
|
|
This can be copied to, for example, `/usr/local/share/powershell` or packaged.
|
2016-03-30 23:15:15 +02:00
|
|
|
|
|
|
|
[issue #673]: https://github.com/PowerShell/PowerShell/issues/673
|