Tested building https://github.com/trolleyman/cuda-macros with this (the `cuda-macros-test` crate) and it builds & links correctly. Haven't had a chance to test that this runs yet, but will in the morning.
I wasn't sure that this way is the most elegant, but this seemed like the way that did the least amount of changes. I am also not sure that this is the correct way of doing this, especially regarding cross-compiling, but it gets it up and running at least.
To test you can do a `cargo build` in the root of the repo linked above. The build stuff is a bit hacky, but essentially it generates the CUDA function below & calls it.
```c
extern "C" __global__ void hello(int32_t* x, int32_t y) {
printf("Hello from block %d, thread %d (y=%d)\n", blockIdx.x, threadIdx.x, y);
*x = 2;
}
```
```rust
extern "C" unsafe fn hello(x: *mut i32, y: i32);
```
If it isn't set, fallback to the previous setting of `-miphoneos-version-min=7.0` for real devices and `mios-simulator-version-min=7.0` for simulators.
Pick the correct softfloat mode based on bitness:
- `-mabi=lp64` for 64 bit RISC-V
- `-mabi=ilp32` for 32-bit RISC-V
Currently it fails for rv32 due to a conflict between the ABI and arch:
cc1: error: ABI requires -march=rv64
Rust's linker cannot currently handle gcc's fPIC compilation units
for RISC-V targets:
= note: rust-lld: error:
.got section detected in the input files. Dynamic relocations are not
supported. If you are linking to C code compiled using the `gcc` crate
then modify your build script to compile the C code _without_ the
-fPIC flag. See the documentation of the `gcc::Config.fpic` method for
details.
So disable PIC by default for now for `riscv` targets.
Automatically choose the most common name for the toolchain, and add the
command-line arguments to generate code that is compatible with the
chosen architecture.
Fixes#397.
Tests that modify environment variables (e.g. CFLAGS and CXXFLAGS) can
cause tests to fail when run in parallel because they change a shared
context.
This change moves the problematic tests into separate modules. Since
each `tests/*.rs` is compiled as a separate crate, these tests are not
run in parallel with other tests.
In case the temporary director is not deleted, this makes it easy to
find. It also means that it will get removed when `cargo clean` removes
the target directory.