ccompilers 0.2.11

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 48

#ccompilers

A set of classes for easy access to the system С/С++ compilers from the Dart language scripts.

Version: 0.2.11

This tools is a library written in Dart programming language. It is intended to compile C/C++ source files from Dart scripts.

It can be used in conjunction with build_tools.

Here is one of the possible examples of scripts for building the project of the Dart VM native extension:

import "dart:io";
import "package:build_tools/build_shell.dart";
import "package:build_tools/build_tools.dart";
import "package:ccompilers/ccompilers.dart";
import "package:file_utils/file_utils.dart";
import "package:patsubst/patsubst.dart";

void main(List<String> args) {
  const String PROJECT_NAME = "sample_extension";
  const String LIBNAME_LINUX = "lib$PROJECT_NAME.so";
  const String LIBNAME_MACOS = "lib$PROJECT_NAME.dylib";
  const String LIBNAME_WINDOWS = "$PROJECT_NAME.dll";

  // Determine operating system
  var os = Platform.operatingSystem;

  // Setup Dart SDK bitness for native extension
  var bits = DartSDK.getVmBits();

  // Compiler options
  var compilerDefine = {};
  var compilerInclude = ['$DART_SDK/include'];

  // Linker options
  var linkerLibpath = [];

  // OS dependent parameters
  var libname = "";
  var objExtension = "";
  switch (os) {
    case "linux":
      libname = LIBNAME_LINUX;
      objExtension = ".o";
      break;
    case "macos":
      libname = LIBNAME_MACOS;
      objExtension = ".o";
      break;
    case "windows":
      libname = LIBNAME_WINDOWS;
      objExtension = ".obj";
      compilerDefine["DART_SHARED_LIB"] = null;
      linkerLibpath.add('$DART_SDK/bin');
      break;
    default:
      print("Unsupported operating system: $os");
      exit(-1);
  }

  // Set working directory
  FileUtils.chdir("../lib/src");

  // C++ files
  var cppFiles = FileUtils.glob("*.cc");
  if (os != "windows") {
    cppFiles = FileUtils.exclude(cppFiles, "${PROJECT_NAME}_dllmain_win.cc");
  }

  // Object files
  var objFiles = patsubst("%.cc", "%${objExtension}").replaceAll(cppFiles);

  // Makefile
  // Target: default
  target("default", ["build"], null, description: "Build and clean.");

  // Target: build
  target("build", ["clean_all", "compile_link", "clean"], (Target t, Map args) {
    print("The ${t.name} successful.");
  }, description: "Build '$PROJECT_NAME'.");

  // Target: compile_link
  target("compile_link", [libname], (Target t, Map args) {
  }, description: "Compile and link '$PROJECT_NAME'.");

  // Target: clean
  target("clean", [], (Target t, Map args) {
    FileUtils.rm(["*.exp", "*.lib", "*.o", "*.obj"], force: true);
  }, description: "Deletes all intermediate files.", reusable: true);

  // Target: clean_all
  target("clean_all", ["clean"], (Target t, Map args) {
    FileUtils.rm([libname], force: true);
  }, description: "Deletes all intermediate and output files.", reusable: true);

  // Compile on Posix
  rule("%.o", ["%.cc"], (Target t, Map args) {
    var compiler = new GnuCppCompiler(bits);
    var args = ['-fPIC', '-Wall'];
    return compiler.compile(t.sources, arguments: args, define: compilerDefine, include: compilerInclude, output: t.name).exitCode;
  });

  // Compile on Windows
  rule("%.obj", ["%.cc"], (Target t, Map args) {
    var compiler = new MsCppCompiler(bits);
    return compiler.compile(t.sources, define: compilerDefine, include: compilerInclude, output: t.name).exitCode;
  });

  // Link on Linux
  file(LIBNAME_LINUX, objFiles, (Target t, Map args) {
    var linker = new GnuLinker(bits);
    var args = ['-shared'];
    return linker.link(t.sources, arguments: args, libpaths: linkerLibpath, output: t.name).exitCode;
  });

  // Link on Macos
  file(LIBNAME_MACOS, objFiles, (Target t, Map args) {
    var linker = new GnuLinker(bits);
    var args = ['-dynamiclib', '-undefined', 'dynamic_lookup'];
    return linker.link(t.sources, arguments: args, libpaths: linkerLibpath, output: t.name).exitCode;
  });

  // Link on Windows
  file(LIBNAME_WINDOWS, objFiles, (Target t, Map args) {
    var linker = new MsLinker(bits);
    var args = ['/DLL', 'dart.lib'];
    return linker.link(t.sources, arguments: args, libpaths: linkerLibpath, output: t.name).exitCode;
  });

  new BuildShell().run(args).then((exitCode) => exit(exitCode));
}

0.2.10

  • Added parameter logger to CommandLineTool
  • Breaking change in the CommandLineTool and their descendants: all parameters in the constructors now are named parameters

0.2.9

  • Added the possibility passing arguments environment and workingDirectory for the compilers and linkers

0.2.8

  • The order of the arguments was modified. The user defined arguments goes now last

0.2.7

  • Improved the detection of 'DART_SDK' location

0.2.6

  • Corrected the detection of 'DART_SDK' but it is still not fully functional when using multiple Dart SDK

0.2.5

  • Fixed bug in 'MsvcUtils'

0.2.4

  • Improved detection of MS Visual Studio C/C++ Compiler

0.2.3

  • Fixed bug in 'MsLinker'

0.2.2

  • DartSDK.getVmBits() now uses information from SysInfo.userSpaceBitness

0.2.1

  • Changed constructor in GnuLinker, added parameter bits
  • Changed constructor in MsLinker, added parameter bits

0.2.0

  • Added class GnuCCompiler
  • Added class GnuCppCompiler
  • Added class GnuLinker
  • Added class MsCCompiler
  • Added class MsCppCompiler
  • Added class MsLinker
  • Added interface CompilerTool
  • Added interface LinkerTool

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  ccompilers: "^0.2.11"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:ccompilers/ccompilers.dart';
        
Version Uploaded Documentation Archive
0.2.11 Oct 10, 2015 Go to the documentation of ccompilers 0.2.11 Download ccompilers 0.2.11 archive
0.2.10 Feb 5, 2015 Go to the documentation of ccompilers 0.2.10 Download ccompilers 0.2.10 archive
0.2.9 Feb 5, 2015 Go to the documentation of ccompilers 0.2.9 Download ccompilers 0.2.9 archive
0.2.8 Feb 5, 2015 Go to the documentation of ccompilers 0.2.8 Download ccompilers 0.2.8 archive
0.2.7 Jan 5, 2015 Go to the documentation of ccompilers 0.2.7 Download ccompilers 0.2.7 archive
0.2.6 Dec 26, 2014 Go to the documentation of ccompilers 0.2.6 Download ccompilers 0.2.6 archive
0.2.5 Dec 25, 2014 Go to the documentation of ccompilers 0.2.5 Download ccompilers 0.2.5 archive
0.2.4 Dec 24, 2014 Go to the documentation of ccompilers 0.2.4 Download ccompilers 0.2.4 archive
0.2.3 Dec 24, 2014 Go to the documentation of ccompilers 0.2.3 Download ccompilers 0.2.3 archive
0.2.2 Dec 18, 2014 Go to the documentation of ccompilers 0.2.2 Download ccompilers 0.2.2 archive

All 20 versions...

Analysis

This feature is new.
We welcome feedback.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Dec 6, 2017
  • Dart: 2.0.0-dev.8.0
  • pana: 0.7.3+1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
50
Health:
Code health derived from static analysis. [more]
78
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall score:
Weighted score of the above. [more]
48

Platforms

Detected platforms: Flutter, server

all of the above

Dependencies

Package Constraint Resolved Available
Direct dependencies
logging any 0.11.3+1
path any 1.5.1
system_info any 0.0.16
Transitive dependencies
file_utils 0.0.23
globbing 0.1.20
Dev dependencies
build_tools any