Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

适配新版本IDE 5.0.1 #27

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ohos_rs_example/build-profile.json5
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
{
"name": "default",
"signingConfig": "default",
"compatibleSdkVersion": "5.0.0(12)",
"runtimeOS": "HarmonyOS"
}
],
"buildModeSet": [
Expand Down
67 changes: 67 additions & 0 deletions ohos_rs_example/entry/oh-package-lock.json5

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

8 changes: 8 additions & 0 deletions ohos_rs_example/entry/oh-package.json5
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@
"author": "",
"license": "",
"dependencies": {
'libarraybuffer.so': 'file:./src/main/cpp/types/libarraybuffer',
'libarray.so': 'file:./src/main/cpp/types/libarray',
'libbasic.so': 'file:./src/main/cpp/types/libbasic',
'libeither.so': 'file:./src/main/cpp/types/libeither',
'libexternal.so': 'file:./src/main/cpp/types/libexternal',
'libhello.so': 'file:./src/main/cpp/types/libhello',
'libtsfn.so': 'file:./src/main/cpp/types/libtsfn',
'libtokio_rt.so': 'file:./src/main/cpp/types/libtokio_rt',
}
}
9 changes: 9 additions & 0 deletions ohos_rs_example/entry/src/main/cpp/types/libarray/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const createArray: () => [];

export const createArrayWithLength: (l: number) => [];

export const setElement: (data: number[], i: number, ele: number) => [];

export const deleteElement: (data: number[], ele: number) => [];

export const hasElement: (data: number[], ele: number) => boolean;
10 changes: 10 additions & 0 deletions ohos_rs_example/entry/src/main/cpp/types/libarray/oh-package.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "libarray.so",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里没有 type 字段?看起来加了类型没什么实际的意义。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因 使用新版 IDE报错无法编译运行项目才手动添加的类型。

"author": "",
"license": "",
"dependencies": {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export const getArraybufferLength: (a: ArrayBuffer) => number;
export const mutateUint8Array: (a: Uint8Array) => undefined;
export const mutateUint16Array: (a: Uint16Array) => undefined;
export const mutateInt16Array: (a: Int16Array) => undefined;
export const mutateFloat32Array: (a: Float32Array) => undefined;
export const mutateFloat64Array: (a: Float64Array) => undefined;
export const mutateI64Array: (a: BigInt64Array) => undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

类型用自动生成的吧,不要手写。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohos能自动生成类型? 我没找到相关文档,要是能自动生成这个PR就可以关了。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohrs 对于使用 napi 修饰的宏会自动生成类型包。也不完全关闭,工程升级到 12 还是有必要的。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohrs 对于使用 napi 修饰的宏会自动生成类型包。也不完全关闭,工程升级到 12 还是有必要的。

ohrs 对于使用 napi 修饰的宏会自动生成类型包。 请教下, 这个我没看到?如何操作才会生成类型文件?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://ohos.rs/docs/basic/quick-start.html
通过 ohrs 构建之后在 dist 文件夹有对应的类型文件,

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
我哪儿操作不对? build 后没类型文件,升级到了最新版本后 还是没。

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "libarraybuffer.so",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
"author": "",
"license": "",
"dependencies": {
}
}
14 changes: 14 additions & 0 deletions ohos_rs_example/entry/src/main/cpp/types/libbasic/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const getBool: () => boolean;

export const getNumber: () => number;

export const getUndefined: () => undefined;

export const getNull: () => null;

export const getArray: () => [];

export const getObject: () => object;

export const bigintAdd: (a: bigint, b: bigint) => bigint;

10 changes: 10 additions & 0 deletions ohos_rs_example/entry/src/main/cpp/types/libbasic/oh-package.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "libbasic.so",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
"author": "",
"license": "",
"dependencies": {
}
}
5 changes: 5 additions & 0 deletions ohos_rs_example/entry/src/main/cpp/types/libeither/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const eitherNumberString: (a: number | string) => number;

export const dynamicArgumentLength: (a?: number) => number;


Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "libeither.so",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
"author": "",
"license": "",
"dependencies": {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const createExternal: (a: number ) => object;
export const getExternalCount: (a: object ) => number;
export const createExternalWithHint: (a: number ) => object;



Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "libexternal.so",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
"author": "",
"license": "",
"dependencies": {
}
}
4 changes: 4 additions & 0 deletions ohos_rs_example/entry/src/main/cpp/types/libhello/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const hello: () => string;



10 changes: 10 additions & 0 deletions ohos_rs_example/entry/src/main/cpp/types/libhello/oh-package.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "libhello.so",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
"author": "",
"license": "",
"dependencies": {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const executeTokioReadFile: (p: string) => Promise<[]>;
export const executeTokioReadFileFailed: (p: string) => Promise<[]>;



Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "libtokio_rt.so",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
"author": "",
"license": "",
"dependencies": {
}
}
4 changes: 4 additions & 0 deletions ohos_rs_example/entry/src/main/cpp/types/libtsfn/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const testTsFn: (a: (...args: number[]) => void) => string;



10 changes: 10 additions & 0 deletions ohos_rs_example/entry/src/main/cpp/types/libtsfn/oh-package.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "libtsfn.so",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
"author": "",
"license": "",
"dependencies": {
}
}
5 changes: 3 additions & 2 deletions ohos_rs_example/entry/src/main/ets/pages/Array.ets
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ struct Array {
})
Button("createArrayWithLength").onClick(() => {
const a = nativeArray.createArrayWithLength(10);
log.info("createArrayWithLength array", String(a.length === 10 && typeof a === "object"));
const l: number = a.length;
log.info("createArrayWithLength array", String(l === 10 && typeof a === "object"));
})
Button("setElement").onClick(() => {
const a = nativeArray.setElement([1, 3, 4], 2, 2);
const a = nativeArray.setElement([1, 3, 4], 2, 2);
log.info("setElement array", String(a.join("")));
})
Button("hasElement").onClick(() => {
Expand Down
2 changes: 1 addition & 1 deletion ohos_rs_example/entry/src/main/ets/pages/Basic.ets
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct Basic {
})
Button("Get Object").onClick(() => {
const o = basic.getObject();
log.info(String(o.test));
log.info(JSON.stringify(o));
})
}
.width('100%')
Expand Down
5 changes: 3 additions & 2 deletions ohos_rs_example/entry/src/main/ets/pages/TokioRT.ets
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct TokioRT {
await tokioRT.executeTokioReadFileFailed(filesDir + '/test.txt');
throw new Error("Unreachable")
} catch (e) {
log.info(e.message);
log.error(e.message);
}
}

Expand All @@ -36,8 +36,9 @@ struct TokioRT {
let file = fs.openSync(filesDir + '/test.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
// 写入一段内容至文件
fs.writeSync(file.fd, "Try to write str.");

const buffers = await Promise.all(
Array.from({ length: 50 }).map((_) => tokioRT.executeTokioReadFile(filesDir + '/test.txt'))
Array.from<number>({ length: 50 }).map(() => tokioRT.executeTokioReadFile(filesDir + '/test.txt'))
);
for (const fileContent of buffers) {
log.info(`${fileContent.toString()}`)
Expand Down
8 changes: 4 additions & 4 deletions ohos_rs_example/entry/src/main/ets/utils/log.ets
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ class Logger {
this.domain = 0xFF00
}

debug(...args: any[]) {
debug(...args: string[]) {
hilog.debug(this.domain, this.prefix, this.format, args)
}

info(...args: any[]) {
info(...args: string[]) {
hilog.info(this.domain, this.prefix, this.format, args)
}

warn(...args: any[]) {
warn(...args: string[]) {
hilog.warn(this.domain, this.prefix, this.format, args)
}

error(...args: any[]) {
error(...args: string[]) {
hilog.error(this.domain, this.prefix, this.format, args)
}
}
Expand Down
5 changes: 2 additions & 3 deletions ohos_rs_example/hvigor/hvigor-config.json5
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"hvigorVersion": "3.0.9",
"modelVersion": "5.0.1",
"dependencies": {
"@ohos/hvigor-ohos-plugin": "3.0.9"
},
"execution": {
// "daemon": true, /* Enable daemon compilation. Default: true */
Expand All @@ -15,4 +14,4 @@
"debugging": {
// "stacktrace": false /* Disable stacktrace compilation. Default: false */
}
}
}
1 change: 0 additions & 1 deletion ohos_rs_example/hvigor/hvigor-wrapper.js

This file was deleted.

48 changes: 0 additions & 48 deletions ohos_rs_example/hvigorw

This file was deleted.

Loading