How to build Flogger from source.

342 views
Skip to first unread message

David Beaumont

unread,
Apr 15, 2018, 11:34:25 AM4/15/18
to Flogger Discuss
If you're here because you're eager to test out Flogger ... Hello and welcome :)

If you just want to use Flogger as a dependency in a Maven based project, or download the pre-built JAR files, then you should just use MavenCentral to access them.

This post is for those that either:
  • Want to jump in on day-1 and play with Flogger
  • Want to build from source directly
Here is a screenshot from IntelliJ showing a working setup, using the individual JAR files (as built by Bazel), along with some test code.


Step 1: Install Bazel

Follow the installation instructions here: https://docs.bazel.build/versions/master/install.html
This is easiest if your system supports the Apt package manager.

Step 2: Clone the Flogger repository

Because I have SSH keys setup, I ran:
  git clone g...@github.com:google/flogger.git

But you can also use:

Step 3: Build Flogger with Bazel

From inside the top-level "flogger" directory of the cloned repo, do:

  bazel build --javacopt='-Xlint:-options' ...    

The '...' is part of the command, not an indication that something's missing.
The reason for the "Xlint" argument is only to suppress otherwise distracting warnings about JDK 1.6 (Flogger is written to be backwards compatible to JDK 1.6).

That command should result in something like:

  INFO: Analysed 41 targets (0 packages loaded).
  INFO: Found 41 targets...
  INFO: Elapsed time: 5.864s, Critical Path: 4.63s
  INFO: Build completed successfully, 98 total actions

which means everything's built and there should now be some additional directories in the repository, including bazel-bin/

Step 4: Put the built jar files somewhere your code can see them

Copy the following jar files to your favourite library directory.
  bazel-bin/api/libapi.jar
  bazel-bin/api/libchecks.jar
  bazel-bin/api/libconfig.jar
  bazel-bin/api/liblazy_args.jar
  bazel-bin/api/libstack.jar
  bazel-bin/api/libsystem_backend.jar
  bazel-bin/api/libtags.jar

At this stage your code should be able to start using Flogger :)

For more information, see https://github.com/google/flogger

Cheers,
    David Beaumont

vankineeni tawrun

unread,
Nov 23, 2018, 10:39:31 AM11/23/18
to Flogger Discuss
David running the Bazel build command in project root shows the following error 

"every rule of type javadoc_library implicitly depends upon the target '@local_jdk//:jdk-default', but this target could not be found because of: no such target '@local_jdk//:jdk-default': target 'jdk-default' not declared in package '' (did you mean 'jre-default'?) 

David Beaumont

unread,
Nov 23, 2018, 11:51:12 AM11/23/18
to vankineen...@gmail.com, flogger...@googlegroups.com
Thank you for raising this. I will ask Ron, who's been handling the open-source packaging (I've not done much of that side of things).

Does switching to jre-default work for you (there's no reason Flogger needs to depend on JDK stuff at runtime) ?

David

--
You received this message because you are subscribed to the Google Groups "Flogger Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flogger-discu...@googlegroups.com.
To post to this group, send email to flogger...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flogger-discuss/854f2ff7-77c2-4119-b60d-5721c63731d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
David Beaumont :: Îñţérñåţîöñåļîžåţîờñ Libraries :: Google
Google Switzerland GmbH., Brandschenkestrasse 110, CH-8002, Zürich - Switzerland

vankineeni tawrun

unread,
Nov 23, 2018, 1:57:54 PM11/23/18
to Flogger Discuss

Can you please tell me how to switch to default-jre. I have been trying but not able to find a resource.

David Beaumont

unread,
Nov 23, 2018, 4:27:14 PM11/23/18
to vankineen...@gmail.com, flogger...@googlegroups.com
I am afraid I don't know (I'm not very involved in the open-source part of this). When the others are back from Thanksgiving weekend, I'm sure someone can help.

Sorry I can't be more helpful at this time.

    David


For more options, visit https://groups.google.com/d/optout.

Ron Shapiro

unread,
Nov 25, 2018, 6:22:38 PM11/25/18
to David Beaumont, vankineen...@gmail.com, flogger...@googlegroups.com

David Beaumont

unread,
Nov 25, 2018, 6:59:14 PM11/25/18
to Ron Shapiro, vankineeni tawrun, flogger...@googlegroups.com
Awesome, thanks! 

    David

Ron Shapiro

unread,
Nov 26, 2018, 6:33:42 PM11/26/18
to David Beaumont, vankineeni tawrun, flogger...@googlegroups.com
This should be fixed at head. Please file an issue if it still doesn't work!

On Fri, Nov 23, 2018 at 4:27 PM 'David Beaumont' via Flogger Discuss <flogger...@googlegroups.com> wrote:

gaura...@gmail.com

unread,
Dec 12, 2019, 11:42:59 PM12/12/19
to Flogger Discuss
This is helpful. Thanks David.

Steffi Ananthan

unread,
Jul 19, 2022, 4:29:02 AM7/19/22
to Flogger Discuss
Hi ! Thanks for the article ! I checked out the latest code (master branch) and tried building it , but I am getting the below error :

I am running on MAC OS . 

bazel 5.2.0-homebrew

java 17.0.3.1 2022-04-22 LTS

As part of api/BUILD file , I can see javabase getting set like this . It is expecting a javac file over there , which it is not able to access !

JAVABASE=$$PWD/$(JAVABASE)
JAR=$$PWD/$(JAVABASE)/bin/jar
$$JAVABASE/bin/javac

Could anyone please help me with what could be the issue here ?

Copying the error snippet below 


ERROR: /Users/msteffi/Downloads/flogger/api/BUILD:65:8: Executing genrule //api:gen_stack_getter_java_lang_access_impl failed: (Exit 126): sandbox-exec failed: error executing command 

  (cd /private/var/tmp/_bazel_msteffi/2ed3d51dc8b42ddc6861675274505da8/sandbox/darwin-sandbox/81/execroot/__main__ && \

  exec env - \

    PATH=/Library/Java/JavaVirtualMachines/jdk-17.0.3.1.jdk/Contents/Home/bin:/opt/homebrew/bin:/Library/Java/JavaVirtualMachines/jdk-17.0.3.1.jdk/Contents/Home/bin:/opt/homebrew/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin \

    TMPDIR=/var/folders/4f/54fc7ntj3pjgk67mmjt8ht4w0000gn/T/ \

  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_msteffi/2ed3d51dc8b42ddc6861675274505da8/sandbox/darwin-sandbox/81/sandbox.sb /var/tmp/_bazel_msteffi/install/7dc25a42d1c3e2ed589cd3c42b3ac535/process-wrapper '--timeout=0' '--kill_delay=15' /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; 

set -eu

TMPDIR=$(mktemp -d)

OUTPUT=$PWD/bazel-out/darwin_arm64-fastbuild/bin/api/stack_getter_java_lang_access_impl.jar

STACK_GETTER_COMMON=bazel-out/darwin_arm64-fastbuild/bin/api/libstack_getter_common.jar

CHECKS=bazel-out/darwin_arm64-fastbuild/bin/api/libchecks.jar

JAVABASE=$PWD/external/openjdk8

JAR=$PWD/external/openjdk8/bin/jar

$JAVABASE/bin/javac -d $TMPDIR -source 7 -target 7 -cp ${STACK_GETTER_COMMON}:${CHECKS} -implicit:none     api/src/main/java/com/google/common/flogger/util/JavaLangAccessStackGetter.java

cd $TMPDIR && $JAR cf $OUTPUT com/google/common/flogger/util/*StackGetter*.class

    ')

/bin/bash: line 8: /private/var/tmp/_bazel_msteffi/2ed3d51dc8b42ddc6861675274505da8/sandbox/darwin-sandbox/81/execroot/__main__/external/openjdk8/bin/javac: cannot execute binary file


Thanks,

Steffi 


Reply all
Reply to author
Forward
0 new messages