Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nix build system for ardupilot #24178

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions Tools/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Tools/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = inputs@{ flake-utils, ... }:
flake-utils.lib.meld inputs [
./nix
];
}
57 changes: 57 additions & 0 deletions Tools/nix/ardupilot-firmware.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{ self, flake-utils, nixpkgs, ... }:
let supported-systems = with flake-utils.lib.system; [ x86_64-linux ];
in flake-utils.lib.eachSystem supported-systems (system:
let
pkgs = import nixpkgs { inherit system; };
python = (pkgs.python39.withPackages
(ps: with ps; [ setuptools future pexpect empy ]));
in {
packages.ardupilot = pkgs.pkgsCross.arm-embedded.stdenv.mkDerivation {
name = "ardupilot";
src = builtins.fetchGit {
url = "https://github.com/ArduPilot/ardupilot.git";
rev = "df2be63e21217b626be53c7c9e98f37410b12126";
ref = "Rover-4.4";
submodules = true;
};
hardeningDisable = [ "all" ];
buildInputs = [ python pkgs.git pkgs.rsync pkgs.gcc ];
nativeBuildInputs = [
python
pkgs.git
pkgs.rsync
pkgs.gcc-arm-embedded
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That isn't our toolchain

pkgs.gcc_multi
pkgs.wafHook
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? Not need

];
patches = [
./patches/ardusim_patches/runnable_status.patch
./patches/ardusim_patches/remove_gcc_Werror.patch
./patches/ardusim_patches/fake_git_rev.patch
];
wafPath = "modules/waf/waf-light";
wafConfigureFlags = [ "--board CubeOrangePlus" ];
wafFlags = [ "rover" ];
postInstall = ''
cp -r build/CubeOrangePlus/bin/* $out/bin/.
'';
system = builtins.currentSystem;
};
packages.ardupilot-fw-flasher = pkgs.stdenv.mkDerivation {
name = "ardupilot-fw-flasher";
src = builtins.fetchGit {
url = "https://github.com/ArduPilot/ardupilot.git";
rev = "df2be63e21217b626be53c7c9e98f37410b12126";
ref = "Rover-4.4";
submodules = true;
};
dontBuild = true;

buildInputs = [ python ];

installPhase = ''
mkdir -p $out/bin
cp Tools/scripts/uploader.py $out/bin/ardupilot-fw-flasher
'';
};
})
39 changes: 39 additions & 0 deletions Tools/nix/ardupilot-sim.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{ self, flake-utils, nixpkgs, ... }:
let supported-systems = with flake-utils.lib.system; [
x86_64-linux
aarch64-linux
aarch64-darwin
];
in flake-utils.lib.eachSystem supported-systems (system:
let
pkgs = import nixpkgs { inherit system; };
inherit (pkgs) lib;
python = (pkgs.python39.withPackages
(ps: with ps; [ setuptools future pexpect empy ]));
in {
packages = flake-utils.lib.flattenTree {
ardusim = pkgs.stdenv.mkDerivation {
name = "ardusim";
src = builtins.fetchGit {
url = "https://github.com/ArduPilot/ardupilot.git";
rev = "df2be63e21217b626be53c7c9e98f37410b12126";
ref = "Rover-4.4";
submodules = true;
};
buildInputs = [ python pkgs.git pkgs.rsync pkgs.gcc ];

nativeBuildInputs = [ pkgs.wafHook ];
patches = [
./patches/runnable_status.patch
./patches/remove_gcc_Werror.patch
./patches/fake_git_rev.patch
];
wafPath = "modules/waf/waf-light";
wafConfigureFlags = [ "--board sitl" ];
wafFlags = [ "rover" ];
postInstall =
" mv Tools/autotest/default_params/rover.parm $out/.;\n mv Tools/mavproxy_modules/ $out/.;\n";
system = builtins.currentSystem;
};
};
})
2 changes: 2 additions & 0 deletions Tools/nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
inputs@{ flake-utils, ... }:
flake-utils.lib.meld inputs [ ./ardupilot-firmware.nix ./ardupilot-sim.nix]
12 changes: 12 additions & 0 deletions Tools/nix/patches/fake_git_rev.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/Tools/ardupilotwaf/git_submodule.py b/Tools/ardupilotwaf/git_submodule.py
index be28216e9c..71ab1f9c33 100644
--- a/Tools/ardupilotwaf/git_submodule.py
+++ b/Tools/ardupilotwaf/git_submodule.py
@@ -157,6 +157,7 @@ def git_submodule_post_fun(bld):
bld.add_post_fun(_post_fun)

def _git_head_hash(ctx, path, short=False):
+ return "2388afcd"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is wrong, fix the build environment to build correctly...

cmd = [ctx.env.get_flat('GIT'), 'rev-parse']
if short:
cmd.append('--short=8')
13 changes: 13 additions & 0 deletions Tools/nix/patches/remove_gcc_Werror.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/libraries/AP_Scripting/wscript b/libraries/AP_Scripting/wscript
index 479fcfe387..f3eb39dcbd 100644
--- a/libraries/AP_Scripting/wscript
+++ b/libraries/AP_Scripting/wscript
@@ -8,7 +8,7 @@ from waflib.TaskGen import after_method, before_method, feature
import os

# these are only used for binding generation, not compilation of the library
-BINDING_CFLAGS="-std=c99 -Wno-error=missing-field-initializers -Wall -Werror -Wextra"
+BINDING_CFLAGS="-std=c99 -Wno-error=missing-field-initializers -Wall -Wextra"
BINDING_CC="gcc"

def configure(cfg):
18 changes: 18 additions & 0 deletions Tools/nix/patches/runnable_status.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/Tools/ardupilotwaf/git_submodule.py b/Tools/ardupilotwaf/git_submodule.py
index be28216e9c..ee46c11185 100644
--- a/Tools/ardupilotwaf/git_submodule.py
+++ b/Tools/ardupilotwaf/git_submodule.py
@@ -69,11 +69,12 @@ class update_submodule(Task.Task):
return out.strip() == head

def runnable_status(self):
+ self.non_fast_forward = []
+ return Task.SKIP_ME
e = self.env.get_flat
cmd = e('GIT'), 'submodule', 'status', '--recursive', '--', e('SUBMODULE_PATH')
out = self.generator.bld.cmd_and_log(cmd, quiet=Context.BOTH, cwd=self.cwd)

- self.non_fast_forward = []

# git submodule status uses a blank prefix for submodules that are up
# to date
1 change: 1 addition & 0 deletions Tools/result
1 change: 1 addition & 0 deletions result
Loading