Skip to content

Commit

Permalink
Build sga by changing to ganim and use gcc
Browse files Browse the repository at this point in the history
  • Loading branch information
utensil committed Nov 3, 2024
1 parent dfc6786 commit 8bd56d1
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ yard-rs/tch-xp/micromamba
Cargo.lock.bak
yard-rs/rust_cpp/libs
notebooks/.ipynb_checkpoints
yard-cpp/.xmake/macosx/arm64
yard-cpp/sga-xp/.xmake/macosx/arm64
yard-cpp/sga-xp/build
13 changes: 13 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,16 @@ prep-uv:
[windows]
prep-uv:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

add-rc LINE:
grep -F '{{LINE}}' ~/.zshrc|| echo '{{LINE}}' >> ~/.zshrc

prep-llvm:
brew install llvm@18
just add-rc 'export LDFLAGS="-L/opt/homebrew/opt/llvm@18/lib/c++ -L/opt/homebrew/opt/llvm@18/lib -lunwind"'
just add-rc 'export PATH="/opt/homebrew/opt/llvm@18/bin:$PATH"'
just add-rc 'export LDFLAGS="-L/opt/homebrew/opt/llvm@18/lib"'
just add-rc 'export CPPFLAGS="-I/opt/homebrew/opt/llvm@18/include"'

prep-gcc:
brew install gcc@13
19 changes: 17 additions & 2 deletions yard-cpp/justfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
set fallback

example_xp := justfile_directory() / "example-xp"
# export CC := `which clang`
# export CXX := `which clang++`
export CC := '/opt/homebrew/Cellar/gcc@13/13.3.0/bin/gcc-13'
export CXX := '/opt/homebrew/Cellar/gcc@13/13.3.0/bin/g++-13'
export LD := '/opt/homebrew/Cellar/gcc@13/13.3.0/bin/g++-13'

default:
just --list
Expand All @@ -22,5 +29,13 @@ new NAME:
git checkout {{BRANCH}}
try-gabm: (prep-ex "https://github.com/utensil/ga-benchmark" "ga-benchmark" "master")
cd {{example_xp / "ga-benchmark"}}

cd {{example_xp / "ga-benchmark"}}

[no-cd]
build:
xmake f --toolchain=gcc --cxx={{CXX}} --cc={{CC}} --ld={{LD}}
xmake -vv

[no-cd]
run: build
xmake run
14 changes: 14 additions & 0 deletions yard-cpp/sga-xp/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "ganim/ga/sga.hpp"
#include "ganim/ga/pga3.hpp"
#include "ganim/ga/print.hpp"
#include <iostream>

int main() {
using namespace ganim::pga3;

auto v = e1 + e2 + e3;

std::cout << v << std::endl;

return 0;
}
8 changes: 8 additions & 0 deletions yard-cpp/sga-xp/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
add_rules("mode.debug") -- , "mode.release")
-- https://xmake.io/#/guide/project_examples?id=integrating-the-c-modules-package
set_languages("c++23")

target("sga-xp")
set_kind("binary")
add_includedirs("$(scriptdir)/../../yard-rs/rust_cpp/libs/ganim/src")
add_files("src/*.cpp")
5 changes: 3 additions & 2 deletions yard-rs/rust_cpp/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ extern crate cpp_build;
fn main() {
let libs = std::env::current_dir().unwrap().join("libs");
let include_gal = libs.join("gal/public");
let include_sga = libs.join("sga");
let include_sga = libs.join("ganim/src/");

cpp_build::Config::new()
.flag("-std=c++20")
.flag("-std=c++2b")
.include(include_gal)
.include(include_sga)
.build("src/lib.rs");

// suppress cargo rerun for edits
println!("cargo:rerun-if-changed=src/run_cpp.rs");
println!("cargo:rerun-if-changed=src/run_sga.rs");
}
4 changes: 3 additions & 1 deletion yard-rs/rust_cpp/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ default:
prep-gal: (clone "https://github.com/jeremyong/gal" "gal" "master")

prep-sga: (clone "https://github.com/sudgy/sga" "sga" "master")
# prep-sga: (clone "https://github.com/sudgy/sga" "sga" "master")

prep-sga: (clone "https://github.com/sudgy/ganim" "ganim" "master")

16 changes: 2 additions & 14 deletions yard-rs/rust_cpp/src/run_sga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,13 @@ use cpp::cpp;

cpp!{{
#include <iostream>
// #include <sga.hpp>
// #include <gal/vga.hpp>
// #include <gal/pga.hpp>
// will need to add #include <bit> for clang
// #include "ganim/ga/sga.hpp"
}}

pub fn hello_pga() {
unsafe {
cpp!([] {
// // Let's work with the projectivized dual space of R3
// using gal::pga::compute;

// // We'll specify our points in R^3
// using point = gal::vga::point<float>;

// // Let's construct a few random points.
// // Each of these points occupies no more than 12 bytes (+ alignment padding).
// point p1{2.4f, 3.6f, 1.3f};
// point p2{-1.1f, 2.7f, 5.0f};
// point p3{-1.8f, -2.7f, -4.3f};
});
}
}
Expand Down

0 comments on commit 8bd56d1

Please sign in to comment.