Skip to content

Commit

Permalink
chore(bors): merge pull request #567
Browse files Browse the repository at this point in the history
567: build: build static binaries with latest pkgs r=tiagolobocastro a=tiagolobocastro

On nixpkgs bug where windows platform is set incorrectly for static
packages: 281596
This can be worked around by using pkgStatic.pkgsCross rather than
the other way around, or simply by replacing the package.
As it happens, the tls build for windows doesn't need openssl, so
we can remove it entirely and skip this issue altogether.
On darwin, libiconv is failing to build, but also seems to not be
required anymore, and so also removing it!


Co-authored-by: Tiago Castro <[email protected]>
  • Loading branch information
mayastor-bors and tiagolobocastro committed Nov 8, 2024
2 parents 4a19268 + 0a7448d commit 1310159
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 23 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions k8s/plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ console-logger = { path = "../../console-logger" }
supportability = { path = "../supportability" }
upgrade = { path = "../upgrade" }
kube-proxy = { path = "../../dependencies/control-plane/k8s/proxy" }
kube-forward = { path = "../../dependencies/control-plane/k8s/forward" }
tokio = { version = "1.41.0" }
anyhow = "1.0.92"
clap = { version = "4.5.20", features = ["color", "derive"] }
Expand Down
13 changes: 13 additions & 0 deletions k8s/plugin/src/resources/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::anyhow;
use clap::Parser;
use openapi::tower::client::Url;
use plugin::{
Expand Down Expand Up @@ -160,6 +161,18 @@ impl From<anyhow::Error> for Error {
}
}

impl From<kube_proxy::Error> for Error {
fn from(e: kube_proxy::Error) -> Self {
if let error @ kube_proxy::Error::Forward {
source: kube_forward::Error::ServiceNotFound { .. },
} = e
{
return Error::Generic(anyhow!("{error}\n Are you on the correct namespace?"));
}
Error::Generic(anyhow!(e))
}
}

/// Initialise the REST client.
pub async fn init_rest(cli_args: &CliArgs) -> Result<(), Error> {
// Use the supplied URL if there is one otherwise obtain one from the kubeconfig file.
Expand Down
2 changes: 1 addition & 1 deletion k8s/supportability/src/collect/persistent_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) enum EtcdError {
K8sResource(K8sResourceError),
IOError(std::io::Error),
Custom(String),
CreateClient(anyhow::Error),
CreateClient(kube_proxy::Error),
}

impl From<StoreError> for EtcdError {
Expand Down
2 changes: 1 addition & 1 deletion k8s/upgrade/src/plugin/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub enum Error {

/// Openapi configuration error.
#[snafu(display("openapi configuration Error: {}", source))]
OpenapiClientConfiguration { source: anyhow::Error },
OpenapiClientConfiguration { source: kube_proxy::Error },

/// Error when opening a file.
#[snafu(display("Failed to open file {}: {}", filepath.display(), source))]
Expand Down
12 changes: 3 additions & 9 deletions nix/lib/rust.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ pkgs }:
let
lib = pkgs.lib;
sources = import ../sources.nix;
in
rec {
makeRustTarget = platform: pkgs.rust.toRustTargetSpec platform;
Expand Down Expand Up @@ -30,7 +31,7 @@ rec {
os = platform: builtins.replaceStrings [ "${platform.qemuArch}-" ] [ "" ] platform.system;
hostPlatform = "${pkgs.rust.toRustTargetSpec pkgs.pkgsStatic.hostPlatform}";
targetPlatform = "${pkgs.rust.toRustTargetSpec pkgs.pkgsCross."${target}".hostPlatform}";
pkgsTarget = if hostPlatform == targetPlatform then pkgs.pkgsStatic else pkgs.pkgsCross."${target}";
pkgsTarget = if hostPlatform == targetPlatform then pkgs else pkgs.pkgsCross."${target}";
pkgsTargetNative = if hostPlatform == targetPlatform then pkgs else if hostOs == targetOs then
import sources.nixpkgs
{
Expand Down Expand Up @@ -63,14 +64,7 @@ rec {
addPreBuild = "";
nativeBuildInputs = with pkgs;
[ pkg-config protobuf paperclip which git ] ++
[ rustPlatformDeps.pkgsTarget.stdenv.cc ] ++
lib.optional (rustPlatformDeps.pkgsTarget.hostPlatform.isDarwin)
[
(rustPlatformDeps.pkgsTarget.libiconv.override {
enableStatic = true;
enableShared = false;
})
];
[ rustPlatformDeps.pkgsTarget.stdenv.cc ];
addNativeBuildInputs = [ ];
buildInputs = if (rustPlatformDeps.pkgsTarget.hostPlatform.isWindows) then with rustPlatformDeps.pkgsTargetNative.windows; [ mingw_w64_pthreads pthreads ] else [ ];
};
Expand Down
12 changes: 1 addition & 11 deletions nix/pkgs/utils/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,9 @@ let
buildKubectlPlugin = { target, release, addBuildOptions ? [ ] }:
let
platformDeps = channel.rustPlatformDeps { inherit target sources; };
# required for darwin because its pkgsStatic is not static!
static_ssl = (platformDeps.pkgsTarget.pkgsStatic.openssl.override {
static = true;
});
rustBuildOpts = channel.rustBuilderOpts { rustPlatformDeps = platformDeps; } // {
buildOptions = [ "-p" "kubectl-plugin" ] ++ addBuildOptions;
${if !pkgs.hostPlatform.isDarwin then "addNativeBuildInputs" else null} = [ platformDeps.pkgsTargetNative.pkgsStatic.openssl.dev ];
addPreBuild = preBuildOpenApi + ''
export OPENSSL_STATIC=1
'' + lib.optionalString (pkgs.hostPlatform.isDarwin) ''
export OPENSSL_LIB_DIR=${static_ssl.out}/lib
export OPENSSL_INCLUDE_DIR=${static_ssl.dev}/include
'';
addPreBuild = preBuildOpenApi;
};
name = "kubectl-plugin";
in
Expand Down

0 comments on commit 1310159

Please sign in to comment.