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

[native_toolchain_c] Add a callback param for CBuilder.run #890

Closed
lindeer opened this issue Jan 15, 2024 · 2 comments
Closed

[native_toolchain_c] Add a callback param for CBuilder.run #890

lindeer opened this issue Jan 15, 2024 · 2 comments
Labels
P3 A lower priority bug or feature request package:native_toolchain_c

Comments

@lindeer
Copy link
Contributor

lindeer commented Jan 15, 2024

For who want to build with custom command, we could add a callback function in cbuilder.dart, something like:

  @override
  Future<void> run({
    required BuildConfig buildConfig,
    required BuildOutput buildOutput,
    required Logger? logger,
    BuilderFunction? callback,
  }) async {

    if (!buildConfig.dryRun) {
      final task = RunCBuilder(
        buildConfig: buildConfig,
        logger: logger,
        sources: sources,
        dynamicLibrary:
            _type == _CBuilderType.library && linkMode == LinkMode.dynamic
                ? libUri
                : null,
        staticLibrary:
            _type == _CBuilderType.library && linkMode == LinkMode.static
                ? libUri
                : null,
        executable: _type == _CBuilderType.executable ? exeUri : null,
        installName: installName,
      );
      await callback == null ? task.run() : callback(task);
    }

and use it in build.dart in package:

  await cbuilder.run(
    buildConfig: buildConfig,
    buildOutput: buildOutput,
    logger: Logger('')..onRecord.listen((record) => print(record.message)),
    callback: (task) {
      await Process.run('make', task.dynamicLibrary);
    },
  );

this could avoid writing redundant code about BuildOutput

@dcharkes
Copy link
Collaborator

Yeah it would be nice to somehow make some logic reusable.

Maybe adding a builder function is not completely the right thing to do. Instead maybe we should introduce some AbstractBuilder class with a bunch of facilities that CBuilder extends for example.

@dcharkes dcharkes added the P3 A lower priority bug or feature request label Jan 15, 2024
@lindeer
Copy link
Contributor Author

lindeer commented Mar 29, 2024

finished in native_assets_builder-v0.6.0

@lindeer lindeer closed this as completed Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 A lower priority bug or feature request package:native_toolchain_c
Projects
None yet
Development

No branches or pull requests

2 participants