forked from M-Labs/nac3
1
0
Fork 0

support both 32 and 64 bit

This commit is contained in:
abdul124 2024-08-05 11:37:52 +08:00
parent 2237137f1a
commit 966f50194f
7 changed files with 66 additions and 8 deletions

View File

@ -3,6 +3,7 @@ name = "nac3standalone"
version = "0.1.0" version = "0.1.0"
authors = ["M-Labs"] authors = ["M-Labs"]
edition = "2021" edition = "2021"
build = "build.rs"
[dependencies] [dependencies]
parking_lot = "0.12" parking_lot = "0.12"

21
nac3standalone/build.rs Normal file
View File

@ -0,0 +1,21 @@
use std::env;
use std::process::Command;
fn main() {
const FILE: &str = "demo/linalg/src/lib.rs";
println!("cargo:rerun-if-changed={FILE}");
let current_dir = env::current_dir().unwrap();
let linalg_dir = current_dir.join("demo").join("linalg");
env::set_current_dir(&linalg_dir).unwrap();
let output = Command::new("nix-build").current_dir(&linalg_dir).output().unwrap();
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
eprintln!("nix-build failed: {}", stderr);
std::process::exit(1);
}
env::set_current_dir(current_dir).unwrap();
}

View File

@ -1,6 +0,0 @@
#!/usr/bin/env bash
# Uses rustup to compile the linalg library for i386 and x86_84 architecture
nix-shell -p rustup --command "RUSTC_BOOTSTRAP=1 cargo build -Z unstable-options --target x86_64-unknown-linux-gnu --out-dir liblinalg/x86_64"
nix-shell -p rustup --command "RUSTC_BOOTSTRAP=1 RUSTFLAGS=\"-C target-cpu=i386 -C target-feature=+sse2\" cargo build -Z unstable-options --target i686-unknown-linux-gnu --out-dir liblinalg/i386"

View File

@ -0,0 +1,42 @@
{ pkgsPath ? <nixpkgs>, crossSystem ? null }:
let
mozOverlay = import (
builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz
);
pkgs = import pkgsPath {
overlays = [ mozOverlay ];
inherit crossSystem;
};
targets = ["i686-unknown-linux-gnu" "x86_64-unknown-linux-gnu"];
in
with pkgs;
pkgs.rustPlatform.buildRustPackage {
name = "linalg";
src = ./.;
cargoLock = {
lockFile = ./Cargo.lock;
};
nativeBuildInputs = [
(buildPackages.buildPackages.latest.rustChannels.stable.rust.override { inherit targets; })
];
buildPhase = ''
${builtins.concatStringsSep "\n" (map (target:
''
cargo build --release --target ${target}
''
) targets)}
'';
installPhase = ''
mkdir -p $out/lib
${builtins.concatStringsSep "\n" (map (target:
''
cp target/${target}/release/liblinalg.a $out/lib/liblinalg-${target}.a
''
) targets)}
'';
}

View File

@ -56,14 +56,14 @@ if [ -z "$i386" ]; then
cd linalg && cargo build -q && cd .. cd linalg && cargo build -q && cd ..
clang -c -std=gnu11 -Wall -Wextra -O3 -o demo.o demo.c clang -c -std=gnu11 -Wall -Wextra -O3 -o demo.o demo.c
clang -lm -Wl,--no-warn-search-mismatch -o demo module.o demo.o linalg/liblinalg/x86_64/liblinalg.a clang -lm -Wl,--no-warn-search-mismatch -o demo module.o demo.o linalg/result/lib/liblinalg-x86_64-unknown-linux-gnu.a
else else
# Enable SSE2 to avoid rounding errors with X87's 80-bit fp precision computations # Enable SSE2 to avoid rounding errors with X87's 80-bit fp precision computations
$nac3standalone --triple i386-pc-linux-gnu --target-features +sse2 "${nac3args[@]}" $nac3standalone --triple i386-pc-linux-gnu --target-features +sse2 "${nac3args[@]}"
clang -m32 -c -std=gnu11 -Wall -Wextra -O3 -msse2 -o demo.o demo.c clang -m32 -c -std=gnu11 -Wall -Wextra -O3 -msse2 -o demo.o demo.c
clang -m32 -lm -Wl,--no-warn-search-mismatch -o demo module.o demo.o linalg/liblinalg/i386/liblinalg.a clang -m32 -lm -Wl,--no-warn-search-mismatch -o demo module.o demo.o linalg/result/lib/liblinalg-i686-unknown-linux-gnu.a
fi fi
if [ -z "$outfile" ]; then if [ -z "$outfile" ]; then