-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add powershell build file * add dart ci test * add github action dart env
- Loading branch information
Showing
10 changed files
with
254 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
$PROJECT_DIR = Get-Location | ||
$RUAPU_API_DIR = Join-Path -Path $PROJECT_DIR -ChildPath "ruapu-api" | ||
$BUILD_DIR = Join-Path -Path $PROJECT_DIR -ChildPath "build" | ||
|
||
New-Item -ItemType Directory -Force -Path $BUILD_DIR | ||
Set-Location $BUILD_DIR | ||
|
||
cmake $RUAPU_API_DIR | ||
cmake --build $BUILD_DIR | ||
|
||
if ($LASTEXITCODE -ne 0) { | ||
Write-Host "Build Error!!! Plz Check!!!" | ||
exit 1 | ||
} | ||
|
||
Set-Location $PROJECT_DIR | ||
|
||
dart pub get | ||
|
||
dart run main.dart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
PROJECT_DIR=$(pwd) | ||
RUAPU_API_DIR="$PROJECT_DIR/ruapu-api" | ||
BUILD_DIR="$PROJECT_DIR/build" | ||
|
||
mkdir -p "$BUILD_DIR" | ||
cd "$BUILD_DIR" || exit | ||
|
||
cmake "$RUAPU_API_DIR" | ||
cmake --build "$BUILD_DIR" | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "Build Error!!! Plz Check!!!" | ||
exit 1 | ||
fi | ||
|
||
cd "$PROJECT_DIR" || exit | ||
|
||
dart pub get | ||
|
||
dart run main.dart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'dart:io'; | ||
import 'ruapu_api.dart'; | ||
import 'package:path/path.dart' as path; | ||
|
||
void main() { | ||
var libraryPath = | ||
path.join(Directory.current.path, 'build', 'libruapu.so'); | ||
|
||
if (Platform.isMacOS) { | ||
libraryPath = | ||
path.join(Directory.current.path, 'build', 'libruapu.dylib'); | ||
} | ||
|
||
if (Platform.isWindows) { | ||
libraryPath = path.join( | ||
Directory.current.path, 'build', 'Debug', 'ruapu.dll'); | ||
} | ||
|
||
Ruapu ruapu = Ruapu(libraryPath); | ||
|
||
ruapu.init(); | ||
|
||
List<String> isas = ruapu.rua(); | ||
print("This CPU Support:"); | ||
for (String isa in isas) { | ||
print(isa); | ||
} | ||
print("================="); | ||
|
||
String isaToCheck = 'aes'; | ||
bool isSupported = ruapu.supports(isaToCheck); | ||
print('Does the system support $isaToCheck? $isSupported'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: dartRuapu | ||
version: 1.0.0 | ||
description: >- | ||
Use ruapu with Dart. | ||
publish_to: none | ||
|
||
environment: | ||
sdk: ^3.4.0 | ||
|
||
dependencies: | ||
path: ^1.9.0 | ||
ffi: ^1.0.0 | ||
|
||
dev_dependencies: | ||
lints: ^4.0.0 | ||
test: ^1.25.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
cmake_minimum_required(VERSION 3.7 FATAL_ERROR) | ||
project(ruapu_library VERSION 1.0.0 LANGUAGES C) | ||
add_library(ruapu_library SHARED ruapu.c ruapu.def) | ||
include_directories(../../) | ||
|
||
set_target_properties(ruapu_library PROPERTIES | ||
PUBLIC_HEADER ../../ruapu.h | ||
VERSION ${PROJECT_VERSION} | ||
SOVERSION 1 | ||
OUTPUT_NAME "ruapu" | ||
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Hex_Identity_ID_Goes_Here" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#define RUAPU_IMPLEMENTATION | ||
#include "ruapu.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
LIBRARY ruapu | ||
EXPORTS | ||
ruapu_rua | ||
ruapu_supports | ||
ruapu_init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'dart:ffi'; | ||
import 'package:ffi/ffi.dart'; | ||
|
||
|
||
typedef RuapuRUA_C = Pointer<Pointer<Utf8>> Function(); | ||
typedef RuapuRUA_Dart = Pointer<Pointer<Utf8>> Function(); | ||
|
||
typedef RuapuInit_C = Void Function(); | ||
typedef RuapuInit_Dart = void Function(); | ||
|
||
typedef RuapuSupports_C = Int32 Function(Pointer<Utf8>); | ||
typedef RuapuSupports_Dart = int Function(Pointer<Utf8>); | ||
|
||
class Ruapu { | ||
final DynamicLibrary _nativeLib; | ||
|
||
Ruapu(String libraryPath) : _nativeLib = DynamicLibrary.open(libraryPath); | ||
|
||
/// Init the ruapu environment | ||
void init() { | ||
final RuapuInit_Dart ruapu_init = _nativeLib | ||
.lookup<NativeFunction<RuapuInit_C>>('ruapu_init') | ||
.asFunction(); | ||
ruapu_init(); | ||
} | ||
|
||
/// Get the ISA support list of the CPU | ||
List<String> rua() { | ||
final RuapuRUA_Dart ruapu_rua = _nativeLib | ||
.lookup<NativeFunction<RuapuRUA_C>>('ruapu_rua') | ||
.asFunction(); | ||
|
||
Pointer<Pointer<Utf8>> result = ruapu_rua(); | ||
|
||
List<String> isas = []; | ||
int index = 0; | ||
while (true) { | ||
Pointer<Utf8> strPtr = result.elementAt(index).value; | ||
if (strPtr.address == 0) break; | ||
String str = strPtr.toDartString(); | ||
isas.add(str); | ||
index++; | ||
} | ||
|
||
return isas; | ||
} | ||
|
||
/// Check the support status of a given isa | ||
bool supports(String isa) { | ||
final Pointer<Utf8> cIsa = isa.toNativeUtf8(); | ||
|
||
final RuapuSupports_Dart ruapu_supports = _nativeLib | ||
.lookup<NativeFunction<RuapuSupports_C>>('ruapu_supports') | ||
.asFunction(); | ||
|
||
int result = ruapu_supports(cIsa); | ||
|
||
malloc.free(cIsa); | ||
|
||
return result != 0; | ||
} | ||
|
||
} |