Skip to content

Commit

Permalink
fix: trying to fix cross-compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
levydsa committed Nov 6, 2024
1 parent dfe3ce8 commit 5576d94
Show file tree
Hide file tree
Showing 9 changed files with 2,155 additions and 57 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ test*.db
*.o
local.db
example
.direnv/
14 changes: 7 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ tracing = "0.1.40"
once_cell = "1.19.0"

[build-dependencies]
bindgen = "0.65.1"
bindgen = "0.69.5"
24 changes: 12 additions & 12 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use std::path::PathBuf;
fn main() {
println!("cargo:rerun-if-changed=./libsql.h");

let bindings = bindgen::Builder::default()
.header("libsql.h")
.rustified_enum("libsql_type_t")
.rustified_enum("libsql_cypher_t")
.rustified_enum("libsql_tracing_level_t")
.derive_default(true)
.generate()
.expect("Unable to generate bindings");
// let bindings = bindgen::Builder::default()
// .header("libsql.h")
// .rustified_enum("libsql_type_t")
// .rustified_enum("libsql_cypher_t")
// .rustified_enum("libsql_tracing_level_t")
// .derive_default(true)
// .generate()
// .expect("Unable to generate bindings");

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
// let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
// bindings
// .write_to_file(out_path.join("bindings.rs"))
// .expect("Couldn't write bindings!");
}
23 changes: 22 additions & 1 deletion flake.lock

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

78 changes: 43 additions & 35 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,53 @@

inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils = {
url = "github:numtide/flake-utils";
};
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
zcc = target: pkgs.writeShellScriptBin "zcc" ''
filtered_args=()
for arg in "$@"; do
if [[ $arg != "--target="* ]]; then
filtered_args+=("$arg")
fi
done
${pkgs.zig}/bin/zig cc -target ${target} "''${filtered_args[@]}"
'';
in
{
formatter = pkgs.nixpkgs-fmt;
devShells.default =
with pkgs;
mkShell {
nativeBuildInputs = [
zig
pkg-config
];
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
config.allowUnsupportedSystem = true;
};
in
{
formatter = pkgs.nixpkgs-fmt;
devShells.default =
with pkgs;
mkShell {
nativeBuildInputs = [
zig
pkg-config
rust-bindgen
cmake
];

buildInputs = [
cmake
] ++ lib.optionals stdenv.isDarwin [
iconv
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.CoreFoundation
darwin.apple_sdk.frameworks.SystemConfiguration
darwin.apple_sdk.frameworks.CoreServices
];
buildInputs = [
] ++ lib.optionals stdenv.isDarwin [
iconv
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.CoreFoundation
darwin.apple_sdk.frameworks.SystemConfiguration
darwin.apple_sdk.frameworks.CoreServices
];

CC_aarch64_unknown_linux_gnu = "${zcc "aarch64-linux-gnu"}/bin/zcc";
};
});
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-Ctarget-feature=-crt-static";
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER =
"${pkgs.pkgsCross.musl64.stdenv.cc}/bin/x86_64-unknown-linux-musl-gcc";

CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-Ctarget-feature=-crt-static";
CC_aarch64_unknown_linux_musl =
"${pkgs.pkgsCross.aarch64-multiplatform-musl.stdenv.cc}/bin/aarch64-unknown-linux-musl-gcc";
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER =
"${pkgs.pkgsCross.aarch64-multiplatform-musl.stdenv.cc}/bin/aarch64-unknown-linux-musl-gcc";
};
});
}
Loading

0 comments on commit 5576d94

Please sign in to comment.