0

In Flash Builder 4.6, when managing a Flex project, under the Build Path options for a Flex Library Project, I can select between "external" and "Merged into code" Framework linkage, with "external" being the default.

How can I use external linkage when calling compc directly?

It seems like compc by default puts the Flex components in the library-path section instead of in the external-library-path section (looking at the generated -dump-config file).

It seems like the option available in Flash Builder ought to be accessible through some option on compc or through some combination of arguments. I've looked through the compc options documentation and unfortunately have come up empty. Any help would be appreciated.

Steven
  • 17,796
  • 13
  • 66
  • 118
  • Why do you want to do this? The "External / Merged into Code" is really a runtime dependency and there is no runtime for a SWC. When creating a SWF that uses a SWC, the Flex Compiler will automatically optimized out unused classes when creating the SWF. – JeffryHouser Jun 14 '12 at 15:23
  • My objective is to make a SWC that is compatible with client apps with a variety of Flex versions. For instance, when I used the [as3commons-logging](http://www.as3commons.org/as3-commons-logging/index.html) SWC, it worked with Flex 3.5 projects as well as 4.6 projects. It seems like this is the standard way of distributing SWCs (with external Flex framework linking) and is the default when building from the Flash Builder. When the SWC is compiled with static linking, it makes for a larger SWC and one that results in compile-time errors in newer projects. – Steven Jun 14 '12 at 15:29
  • @www.Flextras.com I do this all the time: it makes your libraries more lightweight, which is important if you wish to use them as RSL's. The framework classes will be loaded by the main application anyway, so you don't need link them again in your libraries. I never understood why this isn't the default for compc. – RIAstar Jun 14 '12 at 16:22

1 Answers1

2

First have a look at the flex-config.xml file. You'll find it in [flex_sdk_path]/frameworks/flex-config.xml. Now find the nodes called runtime-shared-library-path. Here you'll find a list of all the libraries that will be merged when you compile with compc (the nodes are called runtime-shared-library-path because RSL is the default linkage when you use mxmlc). These are the files that you need to link externally.

You have two options to do this:

  1. Create your own config file in which you translate all those runtime-shared-library-path nodes to external-library-path nodes. Load this file instead of the default by adding -load-config=my-config.xml to the compiler command.
  2. Keep the default config file but override the linkage with command options. Simply add each swc to the external-library-path: -external-library-path+=libs/framework.swc and so forth.

When you compile an application with mxmlc though, the default linkage is RSL. You may want to override this too and make it 'merged'. In this case you'll first have to reset the RSL path: -runtime-shared-library-path= (that's right, nothing after the =). Then add each swc to the -library-path: -library-path+=libs/framework.swc


Alternatively (warning! shameless self-promotion on the way), you could use a build tool called GradleFx. If you create a build file with just this line:

type = 'swc'

it will compile your library with the framework linked externally. You can override this default if the need be:

type = 'swc'
frameworkLinkage = 'merged'
RIAstar
  • 11,912
  • 20
  • 37
  • Thanks RIAstar for the detailed answer. I started poking around with flex-config.xml because I realized that's where the defaults were coming from just before I saw your response, but I didn't know about `-load-config` or exactly what params to change, so I appreciate the push in the right direction. Let me explore your two recommended options and report back on my progress. Once I understand how to rig compc up myself, I hope to be able to poke around with GradleFx. From what I've checked out, seems neat! – Steven Jun 14 '12 at 17:42
  • Both options appear to work great! Two questions.. The only hurdle was that Flexrake seems to make a habit of evaluating all paths relative to pwd or the config file being referenced. This prevented option 2 from working out of the box for me since compc complained that `libs/framework.swc` didn't exist. Fortunately, our build tool allowed us to interpolate in the Flex SDK path. Do you know of a Flex-internal way to do it though? Also, it did not appear to my experimentation that clearing `-runtime-shared-library-path` made any difference. Is this expected? – Steven Jun 14 '12 at 19:08
  • @StevenXu 1) I've always used absolute paths; I don't think the compiler can do what you want. 2) You're right, minor mistake of mine: clearing the rsl-path is required if you would like to merge the framework instead of rsl-linking it with mxmlc, it's not required with compc. I suppose you'd rather have to clear `library-path`, but putting the swcs on the external-library-path seems to already supersede that. – RIAstar Jun 14 '12 at 19:39
  • @StevenXu BTW, what is this Flexrake? I've been trying to find information ont it, but couldn't find any. – RIAstar Jun 14 '12 at 19:51
  • thanks for clarifying the ecosystem at work. I'm not quite 100% on the semantics of all the configuration settings, but it's making a lot more sense now. RE: Flexrake, sorry I mistyped. I meant to say Flex :). I got the name mixed up with one of our build tools! – Steven Jun 14 '12 at 20:07